Home  >  Article  >  Web Front-end  >  jQuery获取URL请求参数的方法_jquery

jQuery获取URL请求参数的方法_jquery

WBOY
WBOYOriginal
2016-05-16 15:49:501488browse

本文实例讲述了jQuery获取URL请求参数的方法。分享给大家供大家参考。具体如下:

$.extend({
 getUrlVars: function(){
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++)
  {
   hash = hashes[i].split('=');
   vars.push(hash[0]);
   vars[hash[0]] = hash[1];
  }
  return vars;
 },
 getUrlVar: function(name){
  return $.getUrlVars()[name];
 }
});

调用方法如下:

// Get object of URL parameters
var allVars = $.getUrlVars();
// Getting URL var by its nam
var byName = $.getUrlVar('name');

希望本文所述对大家的jquery程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn