[英]$(window).on('hashchange') Not firing when I change the hash with Jquery programmatically?
[英]Hashchange jQuery plugin - obtaining the current hash when clicking an anchor
我正在使用来自http://benalman.com/projects/jquery-hashchange-plugin/的 hashchange jQuery插件来挂接窗口的location.hash更改时的事件。
我想在散列更改传递新的散列值(通过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
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.