Skip to content

Instantly share code, notes, and snippets.

@guoshuai93
Last active September 6, 2017 06:25
Show Gist options
  • Save guoshuai93/69862c1e9c1316fe5403c9c849364aee to your computer and use it in GitHub Desktop.
Save guoshuai93/69862c1e9c1316fe5403c9c849364aee to your computer and use it in GitHub Desktop.
// 1. location的search操作——解析url字符串,返回包含所有参数的一个对象
function getSearchObj(){
var qs = location.search.length>0 ? location.search.substr(1):'',
args = {},
items = qs.length>0 ? qs.split('&'):[],
item = null,name = null,value = null,i = 0,len = items.length;
for(i = 0;i < len; i++){
item = items[i].split('=');
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if(name.length){
args[name] = value;
}
}
return args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment