2014-02-25 35 views
0

我动态地添加和删除标签。我现在尝试通过指数去一个特定的标签如下:jquery uitabs off by -1

var elem = ('[role="tabpanel"][symbol="'+symbol+'"][exchange="'+exchange+'"]'); 
var index = $(elem).index(); 
$("#tabs").tabs({active: index}); 

相关的HTML代码:

<div id="tabs-1" aria-labelledby="ui-id-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-expanded="false" aria-hidden="true" style="display: none;"></div> 
<div id="tabs-2" aria-labelledby="ui-id-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-expanded="false" aria-hidden="true" style="display: none;" tabcounter="2" symbol="MSFT" exchange="NASDAQ"></div> 
<div id="tabs-3" aria-labelledby="ui-id-3" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-expanded="false" aria-hidden="true" tabcounter="3" symbol="GOOG" exchange="NASDAQ" style="display: none;"></div> 
<div id="tabs-4" aria-labelledby="ui-id-4" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-expanded="true" aria-hidden="false" tabcounter="4" symbol="YHOO" exchange="NASDAQ" style="display: block;"></div> 

为了使它工作,我需要做的:

$("#tabs").tabs({active: index-1}); 

我不确定为什么需要“-1”。

我不知道为什么还是什么我搞乱这里...

回答

0

的计算机科学的大多数事情的索引从0开始,而不是1 jQuery的标签窗口小部件遵循这一惯例。

+0

这应该没问题?由于var index = $(elem).index()不应该自动为我提供正确的索引值(无论计数开始于何处)?? – user1357015