我们可以通过location可以访问到绝大多数对象的信息,但其中访问URL包含的查询字符创的属性并不是很方便.尽管location.search能返回问好到URL末尾的所有内容.但还是没办法访问其中的每个查询字符串参数. 因为我们可以自己创建一个函数,解析返回字符创
function SearchQuert() {
var qs =window.location.search.length>0? location.search.substring(1):console.log('当前没有查询参数');
var items =qs.split('&'),
name, values,item,args={};
for (var i=0; i<items.length; i++){
item =items[i].split("=");
name =decodeURIComponent(item[0]); //转码
values =decodeURIComponent(item[1]);
if (name.length){
args[name]=values;
}
}
return args;
}