Home >Web Front-end >JS Tutorial >Two ways to get address bar parameters using javascript_javascript skills

Two ways to get address bar parameters using javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:24:26772browse

The code is as follows: Give it a try!

Copy code The code is as follows:



Copy code The code is as follows:
<script> <br>String.prototype.getQuery = function(name) <br>{ <br> var reg = new RegExp("(^|&)" name "=([^&]*)(&|$)"); <br> var r = this.substr(this.indexOf( "?") 1).match(reg); <br> if (r!=null) return unescape(r[2]); return null; <br>} <br>var str ="www.abc.com /index.htm?a=1&b=1&c=test test"; <br>alert(str.getQuery("a")); <br>alert(str.getQuery("b")); <br>alert( str.getQuery("c")); <br></script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn