js解析url中的参数
2019-06-16 本文已影响0人
关耳木南
<script type="text/javascript">
getQueryObject("/User/vip_card_manager?useless=219&id=18");
function getQueryObject(url) {
url = url == null ? window.location.href : url;
var search = url.substring(url.lastIndexOf("?") + 1);
var obj = {};
var reg = /([^?&=]+)=([^?&=]*)/g;
search.replace(reg, function (rs, $1, $2) {
var name = decodeURIComponent($1);
var val = decodeURIComponent($2);
val = String(val);
obj[name] = val;
// return rs;
console.log(rs);
});
// return obj;
console.log(obj);
}
</script>
打印结果
