// 根据参数名称获取参数值
function getParamValue(name) {
var paramsArray = getUrlParams();
if (paramsArray != null) {
for (var i = 0; i < paramsArray.length; i++) {
for (var j in paramsArray[i]) {
if (j == name) {
return paramsArray[i][j];
}
}
}
}
return null;
}
function test()
{
alert("v="+getParamValue("name"));
}
var test1= function()
{
//alert("v1="+getParamValue("name"));
//alert("v2="+GetUrlParam("name"));
//alert("v3="+GetUrlParms("name"));
alert("v4="+getQuery("name"));
}
function GetUrlParam(paramName) {
var url = document.URL; //URL参数,你也可以用document.URL来获取,方法太多了
var oRegex = new RegExp('[/?&]' + paramName + '=([^&]+)', 'i');
//var oMatch = oRegex.exec( window.top.location.search ) ; //获取当前窗口的URL
var oMatch = oRegex.exec(url);
if (oMatch && oMatch.length > 1)
return oMatch[1]; //返回值
else
return '';
}
//获取url参数
function GetUrlParms(name) {
var reg = new RegExp("(^|//?|&)" + name + "=([^&]*)(//s|&|$)", "i");
if (reg.test(location.href))
return unescape(RegExp.$2.replace(//+/g, " "));
return "";
}
var getQuery = function (i) {
var j = location.search.match(new RegExp("[?&]" + i + "=([^&]*)(&?)", "i"));
return j ? j[1] : j
};
</script>
JS获取地址栏参数 :<br>
<a href="#" onclick="test1();">获取参数值</a>
新闻热点
疑难解答