詳細網站可以參考:
JQUERY.URL.JS (http://ajaxcssblog.com/jquery/url-read-request-variables/)
使用方法,
需先引用 jQuery.js ,再加上 jquery.url.js
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="js/jquery.url.min.js"></script>
當你要使用時,只要執行 $.url.param("參數名稱") 就可以取得參數值
舉例來說:
如果你目前的網頁是 http://www.xxx.com.tw?paladin=handsome
$.url.param("paladin") 則會回傳 handsome
但如果所查詢的參數是不存在,則回傳空字串,
同上例: $.url.param("hugo") 就回傳空字串啦。
如果你希望將url 後面所有的參數都抓回存成陣列,則可以使用
$.url.paramAll() 即會回傳所有參數集合的陣列
下載網址:
jquery.url.js
jquery.url.min.js
附上作者原始 source code:
/*
jQuery Url Plugin
* Version 1.0
* 2009-03-22 19:30:05
* URL: http://ajaxcssblog.com/jquery/url-read-get-variables/
* Description: jQuery Url Plugin gives the ability to read GET parameters from the actual URL
* Author: Matthias Jäggli
* Copyright: Copyright (c) 2009 Matthias Jäggli under dual MIT/GPL license.
*/
(function ($) {
$.url = {};
$.extend($.url, {
_params: {},
init: function(){
var paramsRaw = "";
try{
paramsRaw =
(document.location.href.split("?", 2)[1] || "").split("#")[0].split("&") || [];
for(var i = 0; i< paramsRaw.length; i++){
var single = paramsRaw[i].split("=");
if(single[0])
this._params[single[0]] = unescape(single[1]);
}
}
catch(e){
alert(e);
}
},
param: function(name){
return this._params[name] || "";
},
paramAll: function(){
return this._params;
}
});
$.url.init();
})(jQuery);
很好用的外掛,感謝分享
回覆刪除不客氣,美好的事物一定要分享的啊~
刪除超好用謝謝你!
回覆刪除不客氣
刪除