<script><BR> // 获取地址栏的参数数组<BR> function getUrlParams() {<BR> var search = window.location.search;<BR> // 写入数据字典<BR> var tmparray = search.substr(1, search.length).split("&");<BR> var paramsArray = new Array;<BR> if (tmparray != null) {<BR> for (var i = 0; i < tmparray.length; i++) {<BR> var reg = /[=|^==]/; // 用=进行拆分,但不包括==<BR> var set1 = tmparray[i].replace(reg, '&');<BR> var tmpStr2 = set1.split('&');<BR> var array = new Array;<BR> array[tmpStr2[0]] = tmpStr2[1];<BR> paramsArray.push(array);<BR> }<BR> }<BR> // 将参数数组进行返回<BR> return paramsArray;<BR> }
<P> // 根据参数名称获取参数值<BR> function getParamValue(name) {<BR> var paramsArray = getUrlParams();<BR> if (paramsArray != null) {<BR> for (var i = 0; i < paramsArray.length; i++) {<BR> for (var j in paramsArray[i]) {<BR> if (j == name) {<BR> return paramsArray[i][j];<BR> }<BR> }<BR> }<BR> }<BR> return null;<BR> }
<P>function test()<BR>{<BR> alert("v="+getParamValue("name"));<BR>}
<P>var test1= function()<BR>{<BR> //alert("v1="+getParamValue("name"));<BR> //alert("v2="+GetUrlParam("name"));<BR> //alert("v3="+GetUrlParms("name"));<BR> alert("v4="+getQuery("name"));<BR>}
<P>function GetUrlParam(paramName) {<BR> var url = document.URL; //URL参数,你也可以用document.URL来获取,方法太多了<BR> var oRegex = new RegExp('[\?&]' + paramName + '=([^&]+)', 'i');<BR> //var oMatch = oRegex.exec( window.top.location.search ) ; //获取当前窗口的URL<BR> var oMatch = oRegex.exec(url);<BR> if (oMatch && oMatch.length > 1)<BR> return oMatch[1]; //返回值<BR> else<BR> return '';<BR>}
<P>//获取url参数<BR>function GetUrlParms(name) {<BR> var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");<BR> if (reg.test(location.href))<BR> return unescape(RegExp.$2.replace(/\+/g, " "));<BR> return "";<BR>}<BR>var getQuery = function (i) {<br><br>var j = location.search.match(new RegExp("[?&]" + i + "=([^&]*)(&?)", "i"));<br><br>return j ? j[1] : j<br><br>};<BR></script>
JS获取地址栏参数 :
获取参数值