When passing parameters from page A to page B through url, the following two methods can be used to parse url parameters:
Method 1: Regular analysis method
function getQueryString(name) {
var reg = new RegExp("(^|&)" name "= ([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null ) return unescape(r[2]); return null;
}
Call like this:
alert(GetQueryString("Parameter name 1"));
alert(GetQueryString("Parameter name 2"));
alert(GetQueryString ("Parameter name 3"));
Method 2:
Call like this:
If the parameter contains Chinese characters, Pay attention to encoding and decoding:
1. Parameter passing page
Javascript code:
2. Receive parameter page: test02.html
<script> <br>var urlinfo = window.location.href;//Get url <br>var userName = urlinfo.split("?")[1] .split("=")[1];//Split the url to get the parameters after "="<br>$("#userName").html(decodeURI(userName)); <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