js获取请求地址的参数
解决方法:
1.用法
假如请求地址是/vlivevideo.html?id=26,想获取id的值
var param=getParameterByName("id");
2.getParameterByName方法的代码:
getParameterByName: function (name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}