开发者

jquery fill input form with url data

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜