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

Sharing the regular way to get the parameters in the address bar using JavaScript

黄舟
Release: 2017-03-24 15:03:30
Original
1500 people have browsed it

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;
}
Copy after login

Get the type parameter value:

var typeParem = getAddressURLParam(type);
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!