【问题标题】:jQuery's History (and Bookmark) plugin may have a bug?jQuery 的历史(和书签)插件可能有错误?
【发布时间】:2010-07-06 14:29:43
【问题描述】:

我怀疑在文件中 http://github.com/tkyk/jquery-history-plugin/blob/master/samples/ajax/ajax.js

第 13 行和第 14 行

            load(url);
            $.history.load(url);

在 Firefox、Chrome 和 IE 8 中,我看到单击 1、2 或 3 时页面加载了两次。

第 13 行“load(url);”是真的吗?可以删除,因为 $.history.load(url) 会触发用 $.history.init() 注册的函数,它已经做了一个 load()?

熟悉包裹的人可以确认一下吗?

(这是我为 jQuery 找到的最好的 Ajax 历史和书签库。如果有人知道另一个好的,请告诉我们)。

【问题讨论】:

    标签: jquery jquery-plugins


    【解决方案1】:

    是的,您可以删除 load(url) 调用,它会起作用,发生的情况是 init 接受回调,如果位置哈希更改 (which it checks every 100ms),它将再次运行该回调。

    这部分:

    $.history.init(function(url) {
      load(url == "" ? "1" : url);
    });
    

    该函数每 100 毫秒运行一次,if the current location hash (or appState in the plugin) doesn't match what it was previously。实际 click 处理程序中的 load() 调用是除此之外的,因此目前它正在立即运行,并且在 0-100 毫秒后再次运行。

    【讨论】:

    猜你喜欢
    • 2010-12-08
    • 1970-01-01
    • 2011-03-15
    • 2010-11-27
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 2011-03-10
    相关资源
    最近更新 更多