1 1 /** 2 2 * 獲取URL參數的方法 3 3 */ 4 4 $.extend({ //以便於通過$引用該方法 5 5 getUrlVars : function() { //獲取多個參數數組 6 6 var vars = [], hash; 7 7 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 8 8 for (var i = 0; i < hashes.length; i++) { 9 9 hash = hashes[i].split('='); 10 10 vars.push(hash[0]); 11 11 vars[hash[0]] = hash[1]; 12 12 } 13 13 return vars; 14 14 }, 15 15 getUrlVar : function(name) { //獲取指定名稱的參數值 16 16 var p = $.getUrlVars()[name]; 17 17 if (p) { 18 18 return decodeURIComponent(p);//解碼 19 19 } 20 20 return null; 21 21 } 22 22 });