jquery jquery two ways to get URL parameters

Source: Internet
Author: User

jquery the key to getting a URL parameter is to get to the URL, then filter the URL and take out the parameters.
Location.href is get Url,location.search is get url "? "After the string, that is, the parameters section.
method One:
function request (paras) {         var url = location.href;         var parastring = url.substring (Url.indexof ("?") +1,url.length). Split ("&");         var paraobj = {} for         (i=0; j=parastring[i]; i++) {         paraobj[j.substring (0,j.indexof ("=")). toLowerCase ()] = J.substring (j.indexof ("=") +1,j.length);         }         var returnvalue = Paraobj[paras.tolowercase ()];         if (typeof (returnvalue) = = "undefined") {         return "";         } else{         return returnvalue;}         }

Take the parameter value (take the value of "id" for example): request ("id").
The toLowerCase method returns a string with the letters in the string converted to lowercase letters. The processing here is that the parameters are not case-sensitive.
Method Two:
var Request = new Object (); Request = Getrequest (); function getrequest () {  var url = location.search;  var therequest = new Object ();  if (Url.indexof ("?")! =-1) {     var str = url.substr (1);     STRs = Str.split ("&");     for (var i = 0; i < strs.length; i++) {        therequest[strs[i].split ("=") [0]]=decodeuri (Strs[i].split ("=") [1]);     }  }  return therequest; }
take the parameter value (take the value of "id" for example): request["id"].

Author: Li Li
Sign: Life does not have too many illusions, but to have more action.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

jquery jquery two ways to get URL parameters

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.