我正在使用 http://benalman.com/projects/jquery-hashchange-plugin/ 的 hashchange jQuery 插件当窗口的 location.hash 更改时 Hook 事件。
我想在哈希更改时触发一个函数,传递新的哈希值(通过 event.fragment
获得)和当前哈希值(事件触发之前的值) .
这是我想要实现的目标的一个片段:
$(window).bind('hashchange', function(event){
myFunction(event.fragment, /* currentHash */);
});
这可能吗?
最佳答案
该位置有一处特性:
$(window).bind('hashchange', function(event){
myFunction(event.fragment, location.hash);
});
或者,自己存储:
var lastHash = location.hash; //set it initially
$(window).bind('hashchange', function(event){
myFunction(event.fragment, hashLash); //previous hash
lastHash = location.hash; //update it
});
关于javascript - Hashchange jQuery 插件 - 单击 anchor 时获取当前哈希值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4308723/