获取url地址?后面参数值的写法
正则:
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
} // 调用方法
alert(GetQueryString("name"));
alert(GetQueryString("name"));
alert(GetQueryString("name"));
另一种:
function GetUrlParam(paraName) {
var url = document.location.toString();
var arrObj = url.split("?"); if (arrObj.length > 1) {
var arrPara = arrObj[1].split("&");
var arr; for (var i = 0; i < arrPara.length; i++) {
arr = arrPara[i].split("="); if (arr != null && arr[0] == paraName) {
return arr[1];
}
}
return "";
}
else {
return "";
}
}
alert( GetUrlParam("t") )