方法一:
<script type="text/javascript">
<!--
function Request(strName){
var strHref = "www.cnlei.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"));
//-->
</script>
方法二:
<!--
function Request(strName){
var strHref = "www.cnlei.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"));
//-->
</script>
方法二:
<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>
<!--
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>