答案 0 :(得分:1)
试试这会有帮助
function fnGetValueByKey(key)
{
key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + key + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
答案 1 :(得分:0)
我总是使用以下内容,似乎可以正常工作
function urlParam(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];
}
您只需致电urlParam("yourName");
,它就会返回您的值;
答案 2 :(得分:0)
使用getQuery('mykey')访问所需的查询;
function getQuery( key) {
var hu = window.location.search.substring(1), gy = hu.split("&"), val;
keyValue = {};
for ( var i = 0; i < gy.length; i++) {
val = gy[i].split("=");
keyValue[val[0]] = val[1];
}
return keyValue[key];
}