<div class="codetitle"> <span><a style="CURSOR: pointer" data="83243" class="copybut" id="copybut83243" onclick="doCopy('code83243')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code83243"> <br>String.prototype.getParameter = function (key) { <br>var re = new RegExp(key + '=([^&]*)(?:&)?'); <br>return this.match(re) && this.match(re)[1]; <br>}; <br> </div> <br>测试代码: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="74958" class="copybut" id="copybut74958" onclick="doCopy('code74958')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code74958"> <br><script type="text/javascript"> <BR><!-- <BR>String.prototype.getParameter = function (key) { <BR>var re = new RegExp(key + '=([^&]*)(?:&)?'); <BR>return this.match(re) && this.match(re)[1]; <BR>}; <BR>var s = "http://www.baidu.com/index.html?x0=0&x1=1&x2=2&x3=3&x4=http://www.google.com"; <BR>document.write(s.getParameter('x0') + "<br/>"); <BR>document.write(s.getParameter('x1') + "<br/>"); <BR>document.write(s.getParameter('x2') + "<br/>"); <BR>document.write(s.getParameter('x3') + "<br/>"); <BR>document.write(s.getParameter('x4') + "<br/>"); <BR>document.write(s.getParameter('undefined') + "<br/>"); <BR>//--> <BR></script> <br> </div> <br>输出: <br>0 <br>1 <br>2 <br>3