JQuery encapsulates an example of getting parameters in a Url

  • 2020-03-29 23:59:46
  • OfStack

Js pure foreground processing will encounter the problem of passing the parameters of a web page to the next page by way of get.

At this point, js can be used to get the get parameters in the url of the current page. The core statement is:

Window. The location. The href

The detailed code is not explained, there are comments, you read it. Package into jQuery extension package.

 
(function($){ 
$.extend({ 
 
urlGet:function() 
{ 
var aQuery = window.location.href.split("?");//Get parameter
var aGET = new Array(); 
if(aQuery.length > 1) 
{ 
var aBuf = aQuery[1].split("&"); 
for(var i=0, iLoop = aBuf.length; i<iLoop; i++) 
{ 
var aTmp = aBuf[i].split("=");//Separate key from Value
aGET[aTmp[0]] = aTmp[1]; 
} 
} 
return aGET; 
}, 
}); 
})(jQuery); 


Related articles: