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