方法二: <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.cnlei.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; }