This article mainly introduces JavaScriptregular method of obtaining parameters in the address bar, Involving JavaScript regular-based String interception implementation techniques, friends in need can refer to the following
This article describes the method of using JavaScript regularity to obtain parameters in the address bar and shares it with everyone. For reference, the details are as follows:
1. Question:
Get the parameters in the address bar:
If the address in the address bar is:
10.124.36.56:8080/CMOD/index.jsp?name=you&password=123456&type=student
Requires getting the last parameter type in the address bar
2. Implemented JS:
function getAddressURLParam(paramName) { //构造一个含有目标参数的正则表达式的对象 var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)"); //匹配目标参数 var url = window.location.search.substr(1).match(reg); //返回参数值 if(url != null) return unescape(url[2]); return null; }
Get the type parameter value:
var typeParem = getAddressURLParam(type);
Implementation result:
Get the type parameter value: student
The above is the detailed content of Sharing the regular way to get the parameters in the address bar using JavaScript. For more information, please follow other related articles on the PHP Chinese website!