简体   繁体   English

具有一些隐藏选项卡的选定选项卡的索引(jQuery)

[英]Index of Selected Tab with some Hidden Tabs (jQuery)

I have a tab control, and I am trying to get the index of the selected Tab, but I have a problem. 我有一个选项卡控件,并且试图获取所选选项卡的索引,但是我遇到了问题。 I have some hidden tabs before the selected, and I am getting an Index like this: 在选择之前,我有一些隐藏的选项卡,并且正在获取如下所示的索引:

Tab1 - Tab2(hidden) - Tab3(hidden) - Tab4 Tab1-Tab2(隐藏)-Tab3(隐藏)-Tab4

When I try to get the index of Tab4, I get 1, but I want to get a 3 (index from 0 to 3). 当我尝试获取Tab4的索引时,我得到1,但我想得到3(索引从0到3)。

I am using ui.newTab.index() for this, and It ignore the hidden tabs. 我为此使用ui.newTab.index(),它忽略了隐藏的选项卡。

Thanks and good coding!! 谢谢,良好的编码!

Edit . 编辑 This is my code: 这是我的代码:

 jQuery("#testTabs").tabs({ heightStyle: "fill", activate: function (event, ui) { var index = ui.newTab.index(); } }); 

It's in the event. 在活动中。

Are you using jQuery 1.10+ cause 1.8 and earlier (I think) uses select not activate? 您是否正在使用jQuery 1.10+原因1.8及更早版本(我认为)使用选择未激活?

Btw your code has no linked query, make a fiddle with linked jQ and add in HTML while you are at it? 顺便说一句,您的代码没有链接查询,用链接的jQ摆弄琴弦,并在添加HTML时添加?

I refactored someone's Fiddle to have a hidden element and it still works (open the console and see). 我将某人的Fiddle重构为具有隐藏元素,并且该元素仍然有效(打开控制台并查看)。 So I don't think your problem is with hidden. 因此,我认为您的问题不在于隐藏。 Maybe display: none? 也许显示:没有? Than tab is not even in DOM. 比Tab甚至不在DOM中。

<div id="tabs">
  <ul>
    <li><a href="#fragment-1"><span>One</span></a></li>
    <li style="visibility: hidden;"><a href="#fragment-2"><span>Two</span></a></li>
    <li><a href="#fragment-3"><span>Three</span></a></li>
  </ul>
  <div id="fragment-1">
    <p>First tab is active by default:</p>
    <pre><code>$( "#tabs" ).tabs(); </code></pre>
  </div>
  <div id="fragment-2">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
  </div>
  <div id="fragment-3">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
  </div>
</div>

JS JS

$( "#tabs" ).tabs({
  activate: function( event, ui ) {

      console.log(ui.newTab.index());
}
});

this fiddle 这个小提琴

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

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