// 获得上一个页面传过来的参数
function GetOptions() {
var url = window.location.search; //获取url中"?“符后的字串
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]] = decodeURIComponent(strs[i].split("=")[1]);
}
}
return theRequest;
}
var options = GetOptions();
console.log(options );
URL参数解析技巧
本文介绍了一种通过JavaScript从URL中解析参数的方法,实现了一个实用的GetOptions函数,用于获取URL中'?'后的参数,并将其转化为易于操作的对象形式。
1698

被折叠的 条评论
为什么被折叠?



