jQuery的历史记录(和书签)插件可能有错误? [英] jQuery's History (and Bookmark) plugin may have a bug?

查看:95
本文介绍了jQuery的历史记录(和书签)插件可能有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑在档案中 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时,页面被加载了两次.

in Firefox, Chrome, and IE 8, I see that the page is loaded twice when 1, 2, or 3 is clicked on.

第13行"load(url);"是否正确?可以删除,因为$ .history.load(url)会触发向$ .history.init()注册的函数,而该函数已经执行load()了?

Is it true that line 13, "load(url);" can be removed because $.history.load(url) will trigger the function registered with $.history.init(), which does a load() already?

熟悉包装的人可以确认吗?

Can someone familiar with the package confirm this?

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

(This is the best Ajax History and Bookmark library I found for jQuery. If someone knows another good one please let us know).

推荐答案

是的,您可以删除load(url)调用,它将起作用,如果位置哈希值发生变化,则init会进行回调. (每100毫秒检查一次 ),它将再次运行该回调.

Yes, you can remove the load(url) call and it'll work, what happens is that the init takes a callback, if the location hash changes (which it checks every 100ms) it'll run that callback again.

此部分:

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

该函数每100毫秒运行一次,如果当前位置的哈希值(或插件中的appState)与以前的值不符.实际click处理程序中的load()调用是对此的补充,因此当前它正在立即运行,并在0-100ms之后再次运行.

That function gets run every 100ms, if the current location hash (or appState in the plugin) doesn't match what it was previously. The load() call in the actual click handler is in addition to this, so currently it's running instantly, and 0-100ms later again.

这篇关于jQuery的历史记录(和书签)插件可能有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆