var href = window.location.href,
str = href.substring(href.indexOf("#") + 1),
reg = /([^&#?=]+)=(\w*)/g,
result = [];
str.replace(reg, function (str, key, val) {
result = val.split("&");
return str;
})
如果要将url后的参数转为对象
var str = url.substring(url.indexOf("#") + 1),
reg = /([^&#?=]+)=(\w*)/g,
result = [],
obj = {};
result = str.split("&")
console.log(result)
for (var i = 0; i < result.length; i++){
result[i].replace(reg, function (str, key, val) {
obj[key] = val
});
}
return obj