Posted in Javascript onNovember 28, 2012
String.prototype.getParameter = function (key) { var re = new RegExp(key + '=([^&]*)(?:&)?'); return this.match(re) && this.match(re)[1]; };
测试代码:
<script type="text/javascript"> <!-- String.prototype.getParameter = function (key) { var re = new RegExp(key + '=([^&]*)(?:&)?'); return this.match(re) && this.match(re)[1]; }; var s = "http://www.baidu.com/index.html?x0=0&x1=1&x2=2&x3=3&x4=http://www.google.com"; document.write(s.getParameter('x0') + "<br/>"); document.write(s.getParameter('x1') + "<br/>"); document.write(s.getParameter('x2') + "<br/>"); document.write(s.getParameter('x3') + "<br/>"); document.write(s.getParameter('x4') + "<br/>"); document.write(s.getParameter('undefined') + "<br/>"); //--> </script>
输出:
0
1
2
3
Javascript Request获取请求参数如何实现
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@