<script><BR> // 取得網址列的參數數組<BR> function getUrlParams() {<BR> var search = window.location.search;<BR> // 寫入資料字典<BR> var tmparray = search.substr(1, 1. "&");<BR> var paramsArray = new Array;<BR> if (tmparray != null) {<BR> for (var i = 0; i < tmparray.length; i ) {<BR> 正確/[=|^==]/; // 使用=拆分,但不含==<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. }<BR> // 將參數陣列回傳<BR> return paramsArray;<BR> }<BR>
<BR> // 依照參數名稱取得參數值 function getParamValue(name) {<P> var paramsArray = getUrlParams();<BR> if (paramsArray != null) {<var> ; i < paramsArray.length; i ) {<BR> for (var j in paramsArray[i]) {<BR> if (j == name) {<BR> }<BR> }<BR> }<BR> }<BR> return null;<BR> }<BR>
<BR>function test()<BR>{<BR> alert("v=" getParamValue("name"));}<P>
<BR>var test1= function()<BR>{<BR> //alert("v1=" getParamValue("name")); //alert("v2=" GetUrlParam("name")) ;<P> //alert("v3=" GetUrlParms("name"));<BR> alert("v4=" getQuery("name"));<BR>}<BR>
<BR>function GetUrlParam(paramName) {<BR> var url = document.URL; //URL參數,你也可以用document.URL來獲取,方法太多了<BR> var oRegex = new RegExp('[ &]' paramName '=([^&] )', 'i'); //var oMatch = oRegex.exec( window.top.location.search ) ; //取得目前視窗的URL<P> var oMatch = oRegex.exec(url);<BR> if (oMatch && oMatch.length > 1)<BR> return oMatch[1]; //回傳值<BR> else<BR> return '';<BR> }<BR>
<BR>//取得url參數<BR>function GetUrlParms(name) {<BR> var reg = new RegExp("(^|\?|&)" name "=([^&]*)(\s| &|$)", "i"); if (reg.test(location.href))<P> 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取得網址列參數 :
取得參數值