使用到的正则表达式:
[^\?&]?参数名=[^&]+
document.location.getURLPara = function (name) { var reg = new RegExp("[^\?&]?" + encodeURI(name) + "=[^&]+"); var arr = this.search.match(reg); if (arr != null) { return decodeURI(arr[0].substring(arr[0].search("=") + 1)); } return "";}
使用方法:
例如地址:http://localhost/URLParas/Test.aspx?name=mo&帅不帅=太帅了
alert(document.location.getURLPara("帅不帅"));