1,如下举例,页面链接带两个参数
http://localhost:9555/index1.html?token=4ffb21d4f4314d75a6bee347cd1f53d1&username=wandu 2,在js 文档就绪函数中通过GetRequest方法获取对应的参数
var token,username;
$(function () {
token = GetRequest('token');
username = GetRequest('username');
});
3,GetRequest 获取url中参数方法
//获取url中"?"符后的字串 name参数
function GetRequest(name) {
var url = location.search;
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest[name];
}