;(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 hash
location.hash = hash == '' ? name + "=" + encodeURIComponent(value) : hash + "&" + name + "=" + encodeURIComponent(value) ;
} else {
//delete a hash
location.hash = hash;
}
} else {
//get a hash value
if(reg.test(hash)) {
return decodeURIComponent(RegExp.$1);
} else {
return '';
}
}
}
});
})(jQuery);
模拟jquery hash 写了个自己的版本
jQuery URL Hash操作插件
最新推荐文章于 2017-12-19 10:46:13 发布
本文介绍了一个jQuery插件,该插件允许开发者轻松地设置、获取和删除URL哈希中的参数值。通过使用此插件,可以简化单页面应用中对URL哈希进行读写的需求。
947

被折叠的 条评论
为什么被折叠?



