以编程方式选择 jquery ui 选项卡时如何调用 tabselect 事件
我正在使用 jQuery UI 选项卡,并且有一个 tabselect 事件,我使用 api 加载 json 并生成选项卡的内容:
$('#tabs').bind('tabsselect', function(event, ui) {
if (ui.panel.id == "tab1") {
$.getJSON(...)
//load content of tab here
}
}
我还使用历史记录插件进行选项卡链接:
$.address.change(function(event){
$("#tabs").tabs( "select" , hash );
}
所以如果用户转到 mypage# tab1 然后 tab1 会自动加载。问题是 tabselect 事件没有被触发,所以内容没有加载。
我已确保所有这些都在文档加载后发生。如果我手动转到选项卡,那么它可以正常工作,只是在使用 tabs("select", ...); 时不行
我是否必须启用某些选项,以便触发正常事件以编程方式选择选项卡而不是单击它?
I'm using jQuery UI tabs, and I have a tabselect event where I use an api to load json and generate the content of the tab:
$('#tabs').bind('tabsselect', function(event, ui) {
if (ui.panel.id == "tab1") {
$.getJSON(...)
//load content of tab here
}
}
I'm also using a history plugin for tab linking:
$.address.change(function(event){
$("#tabs").tabs( "select" , hash );
}
So if the user goes to mypage#tab1 then tab1 is loaded automatically. The problem is that the tabselect event is not fired, so the content doesn't load.
I've made sure that all of this happens after the document has loaded. If I go to a tab manually then it works fine, just not when using tabs("select", ...);
Is there some option I have to enable so that the normal events are fired for programmatically selecting a tab rather than clicking on it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据选择的文档:
事实上,这确实调用了
tabselect
事件处理程序,如以下示例所示:http://jsfiddle.net/andrewwhitaker/UsnNu/1/
有趣的是,如果以编程方式选择已经处于活动状态的选项卡(在示例中,如果您选择
tab-1< /code> 以编程方式它不会触发事件处理程序)。这可能是问题所在吗?或者
hash
可能包含错误的内容(即您正在使用的历史记录插件有问题)?抱歉,我无法给出明确的答案,但希望这能帮助您找出问题所在。
According to the documentation for select:
This in fact does call the
tabselect
event handler, as you can see by this example:http://jsfiddle.net/andrewwhitaker/UsnNu/1/
Interestingly, it doesn't fire if a tab is selected programmatically that's already active (in the example, if you select
tab-1
programmatically it doesn't fire the event handler). Could this be the problem? Or couldhash
contain the wrong contents (i.e. a problem with the history plugin you're using)?Sorry I couldn't produce a definitive answer, but hopefully that'll help you track down the problem.
尝试加入演出活动。这对我有用,因为当我开始缓存选项卡式状态时,我遇到了同样的问题。
更多信息在这里:http://jqueryui.com/demos/tabs/#event-show
Try hooking into the show event instead. That worked for me as I had the same issue when I started to cache tabbed states.
more information here: http://jqueryui.com/demos/tabs/#event-show