用jQuery UI选项卡更改location.hash [英] changing location.hash with jquery ui tabs

查看:93
本文介绍了用jQuery UI选项卡更改location.hash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在 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屋!

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