//注意url中要含?
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[[]]/g, "\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/+/g, " "));
}
调用:getParameterByName("userID
","?userID=JeoOrCXxyiOFxbYaGL40kw==&userPwd=sdFo2ziUw8HyLRKd4i6GAQ==&userName=高聪
");
得到:userID
值
var parseQuery = function (query) {
var reg = /([^=&s]+)[=s]*([^&s]*)/g;
var obj = {};
while (reg.exec(query)) {
obj[RegExp.$1] = RegExp.$2;
}
return obj;
}
调用:
parseQuery("userID=JeoOrCXxyiOFxbYaGL40kw==&userPwd=sdFo2ziUw8HyLRKd4i6GAQ==&userName=高聪
")
得到