<script language="JavaScript"> <!- var LocString=String(window.document.location.href); function GetQueryString(str){ var rs=new RegExp("(^|)"+str+"=([^&]*)(&|$)","gi").exec(LocString),tmp; if(tmp=rs)return tmp[2]; return "没有这个参数"; } alert("参数一:"+GetQueryString("PP")); alert("参数二:"+GetQueryString("DD")); --> </script>
<script type="text/javascript"> var locString = location.search; function getQueryString(key){ var reg = new RegExp("(&)" + key + "=([^\&]*)(\&?)", "i").exec(locString); return RegExp.$2; } alert(getQueryString("test")); // URL: fileName.html?test=HelloWorld </script>