这里只用了解码decodeURIComponent,不用编码可以吗?另外这个正则怎么理解?
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
}
return null;
}
这段代码是为了获取URL中queryString指定名称的value,只涉及decode场景,无需encode。
至于那段正则就是匹配URL中queryString指定名称的value部分。