【问题标题】:Hashchange jQuery plugin - obtaining the current hash when clicking an anchorHashchange jQuery 插件 - 单击锚点时获取当前哈希值
【发布时间】:2010-11-29 22:27:05
【问题描述】:

我正在使用来自http://benalman.com/projects/jquery-hashchange-plugin/ 的 hashchange jQuery 插件在窗口的 location.hash 更改时连接一个事件。

我想在传递新哈希值(使用event.fragment 获得)和当前哈希值(触发事件之前的值)的哈希更改时触发一个函数。

以下是我想要实现的目标:

$(window).bind('hashchange', function(event){
   myFunction(event.fragment, /* currentHash */);
});

这可能吗?

【问题讨论】:

    标签: javascript jquery jquery-plugins jquery-events


    【解决方案1】:

    该地点有一处房产:

    $(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
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-11
      • 2013-07-01
      • 2012-09-07
      • 2011-06-27
      • 2012-04-21
      • 2012-02-13
      • 2015-05-31
      • 2011-04-26
      相关资源
      最近更新 更多