下面是对获取window.location.search中每一个查询参数函数的封装
var search = window.location.search;
// 以下是对getQueryStringArgs();函数的进一步改进
function getQueryStringArgs1(search){
// 1.取得查询字符串并去掉开头的问号
var searchString = search.length > 0 ?search.substring(1) : “”;
// 2.保存数据的对象
var items = {};
// 3.取得每一项
var args = searchString.length > 0 ? searchString.split(“&”) : [];
var name = null,item = null;
for(var i = 0, length = args.length; i < length; i++ ){
var name = decodeURIComponent(args[i].split(“=”)[0]);
var item = decodeURIComponent(args[i].split(“=”)[1]);
items[name] = item;
}
return items;
};