Home >Web Front-end >JS Tutorial >How to get the parameters after the question mark in the address bar using js_javascript skills

How to get the parameters after the question mark in the address bar using js_javascript skills

PHP中文网
PHP中文网Original
2016-05-16 17:26:241601browse


Copy code The code is as follows:


$(document).ready(function () {
var url = window.location.search;
if (url.indexOf("?") != -1) {
var str = url.substr(1)
strs = str.split ("&");
for (i = 0; i < strs.length; i ) {
alert(strs.length);
alert(strs[i].split("=" )[0]);
alert(strs[i].split("=")[1]);
alert(strs[i].split("=")[0], '=' ,strs[i].split("=")[1], '
');
}
}
})


For example, above The address of strs.length is: 2, the value of strs[0].split("=")[0] is: tn; the value of strs[0].split("=")[1] is: list; the value of strs[1].split("=")[0] is: word; the value of strs[1].split("=")[1] is: liulan

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