<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 = 新しい 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> <スクリプトタイプ="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('unknown') "<br/>"); <br>//--> <br></script> <br> </div> <br>出力: <br>0 <br>1 <br>2 <br>3