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