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

How to get url parameters in JS

小云云
Release: 2018-03-30 09:34:09
Original
1689 people have browsed it

This article mainly shares with you an article about JS getting url parameters and JS sending POST request method in json format. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.


<script type="text/javascript">
Copy after login

1. Get all parameter values ​​​​of the url


function US() {
var name, value;
var str = location.href;
var num = str.indexOf("?");
str = str.substr(num + 1);
var arr = str.split("&");
for (var i = 0; i < arr.length; i++) {
num = arr[i].indexOf("=");
if (num > 0) {
name = arr[i].substring(0, num);
value = arr[i].substr(num + 1);
this[name] = value;
}
}
}
Copy after login

Related recommendations:

js extension examples for obtaining url parameters_javascript skills

Two ways for js to obtain url parameter values_javascript Tips

js Get URL Parameter Code Example Sharing (JS Operation URL)_javascript Tips


The above is the detailed content of How to get url parameters in JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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