jQueryUI 选项卡在特定选项卡上显示()?
我一直在检查所有内容,但似乎无法找到如何使 show() 事件仅对特定选项卡做出反应?
我有以下选项卡:
<div id='tabs' class='ui-tabs'>
<ul class='ui-tabs-nav'>
<li><a href='#tabs-1'>tab 1</a></li>
<li><a href='#tabs-2'>tab 2</a></li>
<li><a href='#tabs-3'>tab 3</a></li>
</ul>
<div id='tabs-1'></div>
<div id='tabs-2'></div>
<div id='tabs-3'></div>
</div>
我希望 show() 事件仅对显示 id 1 做出反应。 是否可以? :)
我的 JS 是:
$(function() {
$('#tabs').tabs({
cookie: {expires: 1},
show: function(event, ui) {
$('#campaigns-attached').delegate('li', 'dblclick', function() { $('#campaigns-non-attached').append(this); var id = this.getAttribute('id'); campaignsAttachRemove(id); });
$('#campaigns-non-attached').delegate('li', 'dblclick', function() { $('#campaigns-attached').append(this); var id = this.getAttribute('id'); campaignsAttachThis(id); });
$('#users-attached').delegate('li', 'dblclick', function() { $('#users-non-attached').append(this); var id = this.getAttribute('id'); usersAttachRemove(id); });
$('#users-non-attached').delegate('li', 'dblclick', function() { $('#users-attached').append(this); var id = this.getAttribute('id'); usersAttachThis(id); });
}
}).disableSelection();
});
usersAttachThis() 和 usersAttachRemove() 是 AJAX 回调函数。 因此,如果我更改选项卡,然后返回到我需要 delegate() 函数的选项卡,它将反应 3 次。
所以我需要说类似
if (tabSelected == "tabs-1") {
$('#users-attached').delegate('li', 'dblclick', function() { $('#users-non-attached').append(this); var id = this.getAttribute('id'); usersAttachRemove(id); });
$('#users-non-attached').delegate('li', 'dblclick', function() { $('#users-attached').append(this); var id = this.getAttribute('id'); usersAttachThis(id); });
}
“OR”的东西,找另一个来做到这一点,而不是 delegate()?
I've been checking everything, but cant seem to find how to make the show() event only react on a specific tab?
I have the following tab:
<div id='tabs' class='ui-tabs'>
<ul class='ui-tabs-nav'>
<li><a href='#tabs-1'>tab 1</a></li>
<li><a href='#tabs-2'>tab 2</a></li>
<li><a href='#tabs-3'>tab 3</a></li>
</ul>
<div id='tabs-1'></div>
<div id='tabs-2'></div>
<div id='tabs-3'></div>
</div>
And i want the show() event only to react on showing id 1.
Is it possible? :)
My JS are:
$(function() {
$('#tabs').tabs({
cookie: {expires: 1},
show: function(event, ui) {
$('#campaigns-attached').delegate('li', 'dblclick', function() { $('#campaigns-non-attached').append(this); var id = this.getAttribute('id'); campaignsAttachRemove(id); });
$('#campaigns-non-attached').delegate('li', 'dblclick', function() { $('#campaigns-attached').append(this); var id = this.getAttribute('id'); campaignsAttachThis(id); });
$('#users-attached').delegate('li', 'dblclick', function() { $('#users-non-attached').append(this); var id = this.getAttribute('id'); usersAttachRemove(id); });
$('#users-non-attached').delegate('li', 'dblclick', function() { $('#users-attached').append(this); var id = this.getAttribute('id'); usersAttachThis(id); });
}
}).disableSelection();
});
The usersAttachThis() and usersAttachRemove() are AJAX callback functions.
So if i change tab and then go back to the tab where i need the delegate() function, it will react 3 times.
So i need to say something like
if (tabSelected == "tabs-1") {
$('#users-attached').delegate('li', 'dblclick', function() { $('#users-non-attached').append(this); var id = this.getAttribute('id'); usersAttachRemove(id); });
$('#users-non-attached').delegate('li', 'dblclick', function() { $('#users-attached').append(this); var id = this.getAttribute('id'); usersAttachThis(id); });
}
OR, find another to do this, instead of delegate()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果可能的话,我很确定不可能,那么组件的一致性就会失效。相反,为什么不让“show”事件在脚本中调用“fauxShow”等函数,并在“fauxShow”中检查是否选择了 id="1" 的选项卡,然后调用函数“realShow”。
有多种方法可以做到这一点,但如果您能解释为什么只希望在一个选项卡上引发事件而不是在其他选项卡上引发事件,可能会有助于获得更好的答案。
If it were possible, and I'm pretty sure it's not, it would invalidate the consistency of the component. Instead why don't you have the "show" event call a function in your script like "fauxShow" and in "fauxShow" check if tab with id="1" was selected and then call function "realShow".
There are dozens of ways to do that, but it might help to get a better answer if you could explain why you only want the event raised on the one tab and not the others.
我找到了答案:)
只需在使用 delegate() 选项之前使用 undelegate() 选项即可。那么就不会再触发两次了。
I found the answer :)
Just use the undelegate() option before using the delegate() option. Then it won't fire twice.