获取url地址参数值

时间:2021-10-19 22:10:50

获取url地址参数值方法:

 function GetQueryString(name)
{
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return unescape(r[2]);
return null;
}

例子:

 var bg = GetQueryString("bg-color");
if (bg) {
alert(bg)
}