1、先截取请求参数字符串;
2、使用decodeURIComponent函数进行解码;
3、正则匹配出参数对象;
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, key, value) { var name = decodeURIComponent(key); var val = decodeURIComponent(value); val = String(val); obj[name] = val; return rs; }); return obj; }
时间: 2024-10-15 07:30:14