<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) { var re = new RegExp(key '=([^&]*)(?:&)?'); <br>回傳this.match(re) && this.match(re)[1]; <br>}; <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><!-- <BR>String.prototype.getParameter = function (key) { <BR>var re = new RegExp(key '=([^&]*) (?:&)?'); <BR>返回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>腳本> <br><br> </div>輸出: <br>0 <br>1 <br>2 <br>3