jQuery提供了很多比较好用的控件,今天用了一下tab,效果类似于浏览器上面的tab。
这些tab的激活(activate)就是显示该tab的内容并关闭其他tab的内容的过程,默认支持click事件激活tab,当然我们也可以通过设置eventtype来将其事件设置为hover或者其他。
今天有个需求就是通过其他位置的控件的点击来增加一个tab,并且激活该tab,那么如果只是企图简单的修改eventtype显然是不可以的。
翻了一下文档,发现了这个接口:
activeType: Boolean or Integer
Default:
0
Which panel is currently open.
Multiple types supported:
- Boolean: Setting
active
tofalse
will collapse all panels. This requires thecollapsible
option to betrue
. - Integer: The zero-based index of the panel that is active (open). A negative value selects panels going backward from the last panel.
Initialize the tabs with the active
option specified:
$( ".selector" ).tabs({ active: 1 });
// getter
var active = $( ".selector" ).tabs( "option", "active" );
// setter
$( ".selector" ).tabs( "option", "active", 1 );
tabs.tabs("refresh");
之前,导致执行有问题。
stackoverflow上面也有跟我有同样遭遇的朋友,http://stackoverflow.com/questions/17581339/manually-activate-tabs-jquery-ui-1-10-3