Home > Web Front-end > JS Tutorial > Obtain parameters in url through regular expressions (graphic tutorial)

Obtain parameters in url through regular expressions (graphic tutorial)

亚连
Release: 2018-05-21 10:27:16
Original
3634 people have browsed it

Below I will bring you a simple implementation of obtaining parameters in the url through regular expressions. Let me share it with you now and give it as a reference for everyone.

url:

http://xxxx.com?name=Charming&id=123

js中:

var name = getUrlParam("name");
/*通过正则获取url中的参数*/
function getUrlParam(name){
   var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
   var r = window.location.search.substr(1).match(reg);
   if(r!=null)return decodeURI(r[2]); return null;
}
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

JavaScript to obtain the city and geographical location of the user

Ajax PHP JavaScript MySQL implements a simple no-refresh online chat room

The relationship between JavaScript calling mode and this keyword binding

The above is the detailed content of Obtain parameters in url through regular expressions (graphic tutorial). 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