您好,欢迎访问一九零五行业门户网

javascript获取地址栏参数代码实例详解

用javascript获取地 址栏参数
//本页地址为:  alert(document.location);   
方法一:
<script type="text/javascript"> <!-- string.prototype.getquery = function(name) { var reg = new regexp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = this.substr(this.indexof("\?")+1).match(reg); if (r!=null) return unescape(r[2]); return null; } var strhref = "www.ceshi.org/index.htm?a=aaa&b=bbb&c=ccc"; alert(strhref.getquery("a")); alert(strhref.getquery("b")); alert(strhref.getquery("c")); //--> </script>
方法二:
<script type="text/javascript"> function geturlpara(paraname){ var surl = location.href; var sreg = "(?:\\?|&){1}"+paraname+"=([^&]*)" var re=new regexp(sreg,"gi"); re.exec(surl); return regexp.$1; } //应用实例:test_para.html?a=11&b=22&c=33 alert(geturlpara("a")); alert(geturlpara("b")); </script>
方法三:
<script type="text/javascript"> <!-- function request(strname){ var strhref = "www.ceshi.org/index.htm?a=aaa&b=bbb&c=ccc"; var intpos = strhref.indexof("?"); var strright = strhref.substr(intpos + 1); var arrtmp = strright.split("&"); for(var i = 0; i < arrtmp.length; i++) { var arrtemp = arrtmp[i].split("="); if(arrtemp[0].touppercase() == strname.touppercase()) return arrtemp[1]; } return ""; } alert(request("a")); alert(request("b")); alert(request("c")); //-->
以上就是javascript获取地址栏参数代码实例详解的详细内容。
其它类似信息

推荐信息