Home >Web Front-end >JS Tutorial >How to get url parameters in JS

How to get url parameters in JS

小云云
小云云Original
2018-03-30 09:34:091741browse

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">

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;
}
}
}

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!

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