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