Skip to content

Instantly share code, notes, and snippets.

@alanerzhao
Last active December 27, 2015 23:49
Show Gist options
  • Save alanerzhao/7409335 to your computer and use it in GitHub Desktop.
Save alanerzhao/7409335 to your computer and use it in GitHub Desktop.
function getQueryStringArgs () {
// URL length get "?" before string
var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
args = {},
//切分成数组
items = qs.length ? qs.split("&") : [],
item = null,
name = null,
value = null,
i = 0,
len = items.length;
for(i;i < len; i++) {
//切分key value
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if(name.length) {
args[name] = value;
}
}
//url return url object
return args;
}
var searchURL = getQueryStringArgs();
console.dir(searchURL);
//遍历所有属性
function outputAttr (element) {
var pairs = [],
pairsObj = {},
name = null,
attrName,
attrValue,
i,
len;
for(i = 0,len = element.attributes.length; i < len; i ++) {
attrName = element.attributes[i].nodeName;
attrValue = element.attributes[i].nodeValue;
pairs.push(attrName +" =" + attrValue);
pairsObj[attrName] = attrValue
}
console.log(pairsObj);
return pairs.join(" ");
}
console.log(outputAttr(mydiv));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment