简体   繁体   English

选项卡上的事件在jquery ui选项卡中取消选择

[英]event on tab deselect in jquery ui tabs

I m using jquery ui tabs 1.8.1 我正在使用jQuery UI选项卡1.8.1

I want to bind an event or a script to run when a tab gets deselected and any other tab is selected 我想绑定一个事件或脚本,以在取消选择某个选项卡并选择任何其他选项卡时运行

for eg. 例如 if i have four tabs and tab four is selected when i select tab 1 or tab 2 then a event should run such that i can stop any timers running in tab 4 如果我有四个选项卡,并且在选择选项卡1或选项卡2时选择了选项卡四,则应运行一个事件,以便我可以停止在选项卡4中运行的任何计时器

Another question related is if im running any timers using this 另一个相关的问题是即时通讯是否使用计时器运行任何计时器

or if im using setInterval using standard jquery 或者如果我使用标准jQuery使用setInterval

it doesn't stop automatically on selecting any other tab... 它不会在选择任何其他选项卡时自动停止...

any solution would be a great help... 任何解决方案都会有很大帮助...

thanks 谢谢

Pradyut Pradyut

India 印度

basically what you want to do is calling an event everytime a tab is selected, except when its tab4, ie.: 基本上,您想要做的就是每次选择一个标签时都调用一个事件, 除非它的tab4,即:

when your tabs header looks somehow like this 当您的标签页标题看起来像这样

<div id="tabs">
  <ul id="tablinks">
    <li><a id="tab1" href="#tabs-1">First</a></li>
    <li><a id="tab2" href="#tabs-2">Second</a></li>
    <li><a id="tab3" href="#tabs-3">Third</a></li>
    <li><a id="tab4" href="#tabs-4">Fourth</a></li>
  </ul>
  <div id="tabs-1"></div>
  <div id="tabs-2"></div>
  <div id="tabs-3"></div>
  <div id="tabs-4"></div>
</div>

then you attach a click event on every a tag in the "tablinks" unordered list, that has not "tab4" as an id: 然后,您将点击事件附加到“ tablinks”无序列表中每个没有ID为“ tab4”的标签上:

$('#tablinks a[id!=tab4]').click(function(e){
  //stoping timers or whatever
});

and concerning your second questions, the link you provided actually holds the answer to it.. 关于第二个问题,您提供的链接实际上包含了答案。

when you create a timer by using "everyTime" or "oneTime" you can pass a label as a parameter, so that you're able to stop your timers whenever you want with the "stopTime" method, ie.: 当使用“ everyTime”或“ oneTime”创建计时器时,可以传递标签作为参数,以便您可以随时使用“ stopTime”方法停止计时器,即:

$(document).everyTime(1000, "doingSomething", function() {
  // NOTE: "doingSomething" is the label of this timer

  // make an annoying bleep sound or whatever
});

now stop this timer by calling 现在通过调用来停止此计时器

$(document).stopTime("doingSomething");

If you bind to the 'tabselect' event, you can determine the currently selected tab. 如果绑定到“ tabselect”事件,则可以确定当前选定的标签。 This will let you do something specific to this tab before the tab switch. 在选项卡切换之前,这将使您可以对此选项卡执行特定的操作。 You can even return false from the handler to prevent the tab switch. 您甚至可以从处理程序返回false,以防止制表符切换。 Try the following in a debugger (like Firebug) at the jQuery UI demo site: http://jqueryui.com/demos/tabs/default.html 在jQuery UI演示站点的调试器(如Firebug)中尝试以下操作: http : //jqueryui.com/demos/tabs/default.html

$('#tabs').bind('tabsselect', function(evt, ui) { 
    console.log($('#tabs').find('li.ui-tabs-selected a').attr('href')); 
});

In the handler you can check the selected tab and do whatever you need for any tab that gets deselected... 在处理程序中,您可以检查选定的选项卡,并为取消选择的任何选项卡执行任何操作...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM