2010-07-06 71 views
0

我在文件 怀疑http://github.com/tkyk/jquery-history-plugin/blob/master/samples/ajax/ajax.jsjQuery的历史(和书签)插件可能有一个错误?

线13和14

  load(url); 
      $.history.load(url); 
在Firefox,铬,和IE 8

,我看到一个1,2,或点击3当页面被加载两次上。

确实是第13行“load(url);”可以被删除,因为$ .history.load(url)将触发用$ .history.init()注册的函数,该函数已经执行了load()。

熟悉包装的人能否证实这一点? (这是我发现的最好的Ajax历史和书签库,如果有人知道另一个好的,请告诉我们)。

回答

2

是的,你可以删除load(url)电话,它会工作,会发生什么init需要回调,如果位置散列改变(which it checks every 100ms)它会再次运行该回调。

这一部分:

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

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

+0

很好......你对JavaScript很熟悉。我们使用的类似软​​件包有这个问题:http://stackoverflow.com/questions/3162579/why-does-really-simple-history-javascript-library-fire-off-event-twice-in-ie-but你知道为什么吗? – 2010-07-06 14:48:31

相关问题