Home  >  Article  >  Web Front-end  >  Sharing the regular way to get the parameters in the address bar using JavaScript

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

黄舟
黄舟Original
2017-03-24 15:03:301492browse

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!

Statement:
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