首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

模拟jquery hash 写了个自个儿的版本

2012-11-23 
模拟jquery hash 写了个自己的版本(function($) {$.extend({hash : function(name , value) {function is

模拟jquery hash 写了个自己的版本

;(function($) {$.extend({hash : function(name , value) {function isString(str) {return typeof str == 'string' && Object.prototype.toString.call(str) === '[object String]';}if(!isString(name) || $.trim(name) == '') return;var reg = new RegExp("[&|#]" + name + "=([^&]*)" , "i");var hash = location.hash;if(value || value === null) {hash = hash.replace(reg , '').replace(/^[#|&]/ , '');if(value !== null) {//set a hashlocation.hash = hash == '' ? name + "=" + encodeURIComponent(value) : hash + "&" + name + "=" + encodeURIComponent(value) ; } else {//delete a hashlocation.hash = hash;} } else {//get a hash valueif(reg.test(hash)) {return decodeURIComponent(RegExp.$1);} else {return '';}}}});  })(jQuery);

热点排行