使用 jquery ui 选项卡更改 location.hash [英] changing location.hash with jquery ui tabs
问题描述
我一直试图找到一种方法将 window.location.hash 更改为 Jquery UI 选项卡.
I've been trying to find a way to change the window.location.hash to the currently selected tab in Jquery UI Tabs.
我试过了:
$("#tabs > ul").tabs();
$("#tabs > ul").bind("tabsshow", function(event, ui) {
window.location.hash = ui.tab;
})
这会导致在更改选项卡时将哈希更改为 #undefined.
This results in changing the hash to #undefined when the tab is changed.
我也试过:
$("#tabs > ul").tabs({
select: function(event, ui) {
window.location.hash = ui.tab }
});
但这似乎根本没有触发.
But this doesn't seem to be triggered at all.
任何帮助将不胜感激.谢谢.
Any help would be appreciated. Thanks.
看起来我最初的问题的一部分与其他地方的 js 干扰有关.接受的答案和其他稍微修改的建议答案都有效.谢谢大家.
It looks like part of my initial problem had something to do with js somewhere else interfering with this. Both the accepted answer and the other suggested answer slightly modified do work. Thanks all.
推荐答案
在你的事件处理函数中 ui.tab
是一个锚元素.您可以像这样检索其哈希值:
In your event handler function ui.tab
is an anchor element. You can retrieve its hash value like this:
$("#tabs > ul").tabs();
$("#tabs > ul").bind("tabsshow", function(event, ui) {
window.location.hash = ui.tab.hash;
})
这对你有用吗?
这篇关于使用 jquery ui 选项卡更改 location.hash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!