【发布时间】:2011-02-28 03:43:11
【问题描述】:
我有这个 jQuery ajax 导航选项卡插件,我使用 CSS-Tricks.com 和 jQuery hashchange event 插件的帮助创建了这个插件(检测不支持它的浏览器中的哈希更改)。
这里的代码有点长,但它是这样的:
第 1 部分)单击选项卡时,它会获取该选项卡的 href 属性并将其添加到浏览器导航栏中,例如 '#tab_name':window.location.hash = $(this).attr("href");
Part 2)当导航栏发生变化(hash变化)时,得到href变化是这样的:window.location.hash.substring(1);(子字符串是只得到'tab_name'没有'#'),然后调用ajax函数获取要显示的信息。
我想在页面被访问时自动触发插件加载第一个标签,所以在代码的开头我放了:
if (window.location.hash === '') { // If no '#' is in the browser navigation bar
window.location.hash = '#tab_1'; // Add #tab_1 to the navigation bar
$(window).trigger('hashchange'); // Trigger a hashchange so 'Part 2' of the plugin calls the ajax function using the '#tab_1' added
}
问题是它在 FF 中有效,但在 Chrome 中无效,我的意思是,一切正常,但似乎 $(window).trigger('hashchange'); 不起作用,因为它没有获得第一个选项卡..
有什么建议吗??
注意:它在前一段时间有效,但突然无效(可能是 Chrome 更新)。
【问题讨论】:
标签: javascript jquery hash