如何使用 Jquery UI 设置默认选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1377037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:18:55  来源:igfitidea点击:

How to set a default tab with Jquery UI

jqueryjquery-uitabs

提问by Lee McAlilly

I'm using Jquery and Jquery UI with the following:

我正在使用 Jquery 和 Jquery UI,如下所示:

$(document).ready(function() {
    $('#tabvanilla > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
});

Right now it automatically sets the first tabs as the default tab that is selected when the document loads. How do I override this and make the second tab the default selected tab when the page loads?

现在它会自动将第一个选项卡设置为文档加载时选择的默认选项卡。如何在页面加载时覆盖它并使第二个选项卡成为默认选择的选项卡?

回答by Mark Hurd

$('#tabvanilla > ul').tabs({ selected: 1 });

More details on the specifications page.

规格页面上的更多详细信息。

回答by Leniel Maccaferri

If you happen to be using jQuery UI >= 1.9, this is how it works:

如果您碰巧正在使用jQuery UI >= 1.9,这就是它的工作原理:

$(".selector" ).tabs({ active: 2 });

More details on the Tabs Widget API page: http://api.jqueryui.com/tabs/#option-active

Tabs Widget API 页面上的更多详细信息:http: //api.jqueryui.com/tabs/#option-active

回答by Elemental

I found this alternate solution which might be preferable in some situations: http://www.markhneedham.com/blog/2010/09/08/jquery-ui-tabs-changing-selected-tab/

我发现这种替代解决方案在某些情况下可能更可取:http: //www.markhneedham.com/blog/2010/09/08/jquery-ui-tabs-changed-selected-tab/