Home >Web Front-end >JS Tutorial >How to get the parameters after the question mark in the address bar using js_javascript skills
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