Home > Web Front-end > JS Tutorial > A brief introduction to the url parameter parse and build functions of JavaScript

A brief introduction to the url parameter parse and build functions of JavaScript

黄舟
Release: 2017-03-23 14:46:33
Original
1610 people have browsed it

The following editor will bring you a brief discussion of javascript’s url parameter parse and buildfunction. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

Parse:

function getParam() {
    var param = new Object()
    var item = new Array();
    if (location.search == "") {
      return param;
    };
    var query = location.search.substring(1);                                                                   
    var list = query.split('&');
    for(var i = 0; i < list.length; i++) {
      item = list[i].split(&#39;=&#39;);
      if (typeof param[item[0]] == "undefined") {
        param[item[0]] = new Array();
      }
      param[item[0]].push(item[1]);
    };
    return param;
  };
Copy after login

Build:

function getUrlByParam(param) {
    var url = "";
    for (field in param) {
      for (index in param[field]) {
        url += "&" + field + "=" + param[field][index];
      };
    };
    return url == "" ? url : url.substring(1);
  };
Copy after login

The above is the detailed content of A brief introduction to the url parameter parse and build functions of JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
How to build/concatenate strings in JavaScript?
From 1970-01-01 08:00:00
0
0
0
javascript - autodesk forge build details
From 1970-01-01 08:00:00
0
0
0
javascript - How to parse this json data
From 1970-01-01 08:00:00
0
0
0
javascript - font not recognized after vue build
From 1970-01-01 08:00:00
0
0
0
javascript - vue webpack npm run build error
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template