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);
精彩评论