开发者

jquery fill input form with url data

开发者 https://www.devze.com 2022-12-18 05:04 出处:网络
how i need fill out a input of my form with jquery. I ha开发者_如何学Pythonve my url: http://example.com/page.html?name=YourName=MarkYou could use a function that returns the value of a querystring p

how i need fill out a input of my form with jquery.

I ha开发者_如何学Pythonve my url: http://example.com/page.html?name=YourName=Mark


You could use a function that returns the value of a querystring parameter and then set the form field accordingly:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
 }

var sName = getParameterByName(name);

Then set the form field value using jquery:

$("#formFieldID").val(sName);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号