Home > Web Front-end > JS Tutorial > body text

Two ways to get address bar parameters using javascript_javascript skills

WBOY
Release: 2016-05-16 19:24:26
Original
719 people have browsed it

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>
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template