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

JavaScript uses regular expressions to obtain a certain parameter on the URL_javascript tips

WBOY
Release: 2016-05-16 16:37:15
Original
1208 people have browsed it
function GetUrlMenuCode() { 
var url = window.location.href; 
var parameter = url.substring(url.indexOf('?') + 1); 
parameter = parameter.split('&'); 
var reg = /MenuCode=/g; 
var menuCode = ""; 
for (var i = 0; i < parameter.length; i++) { 
reg.lastIndex = 0; 
if (reg.test(parameter[i])) { 
menuCode = parameter[i].replace("MenuCode=", ""); 
break; 
} 
} 
return menuCode; 
}
Copy after login

The above example shows a parameter named "MenuCode" being obtained from the url

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