A Brief Introduction to the url parameters parse AND build functions of javascript

Source: Internet
Author: User
The following section will introduce the url parameters parse AND build functions of javascript. I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at the following small series to bring you an article on javascript url parameters parse AND build functions. I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at it with xiaobian.

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('=');      if (typeof param[item[0]] == "undefined") {        param[item[0]] = new Array();      }      param[item[0]].push(item[1]);    };    return param;  };

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);  };

The preceding section briefly introduces the url parameters parse AND build functions of javascript. For more information, see other related articles in the first PHP community!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.