答案 0 :(得分:29)
在我的programming archive我this function:
function querystring(key) {
var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
var r=[], m;
while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
return r;
}
您可以使用它来获取查询字符串值并放入文本框中:
$('#SomeTextbox').val(querystring('q'));
答案 1 :(得分:7)
使用the answer至this question中列出的功能:
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 decodeURIComponent(results[1].replace(/\+/g, " "));
}
然后做这样的事情:
var qParam = getParameterByName('q');
$('#mytextbox').val(qParam);