"jquery" jquery two ways to get URL parameters

Source: Internet
Author: User

The key to jquery getting URL parameters is to get the URL, then filter the URL and take the number of references.
Location.href is the Get URL. Location.search is get url "? "After the string, that is, the part of the parameters.
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 value (take "id" as an example): request ("id").
The toLowerCase method returns a string with the letters in the string converted to lowercase letters. The deal here is that the number of references does not distinguish between uppercase and lowercase.
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 values (take the value of "id" for example): request["id"].



Author: Li Li
Sign: Life does not have too many illusions, but there are many other actions.


"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.