<!--
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.split("=");
if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
}
return "";
}
alert(Request("b"));
alert(Request("c"));
//-->
</>
方法二: < type="text/java">
<!--
String.prototype.getQuery = (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"));
//-->
</>
方法三: < type="text/java">
getUrlPara(paraName){
var sUrl = location.href;
var sReg = "(?://?|&){1}"+paraName+"=([^&]*)"
var re=new RegExp(sReg,"gi");
re.exec(sUrl);
return RegExp.$1;
}
alert(getUrlPara("a"));
alert(getUrlPara("b"));
</>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hanghwp/archive/2007/06/27/1668996.aspx