0

我有 2 个选项卡,并想选择第 2 个选项卡作为选定/活动。我不知道 active/selected 之间有什么区别,但这段代码不起作用:

$(function() {
  $( "#tabs" ).tabs();
  $( "#tabs" ).tabs({ selected: "#tabs-1" });
});

我将其更改为:

$(function() {
  $( "#tabs" ).tabs();
  $( "#tabs" ).tabs({ selected: 2 });
});

并将选定的: 2 更改为 1 或 0 但没有运气。

我会当用户单击一个选项卡时,cookie 应该记录选择,当访问者下次访问时,记住的选项卡应该是活动的。 谢谢

4

1 回答 1

4

selected is not a valid attribute for the jQuery UI tabs widget. You need to use active. http://api.jqueryui.com/tabs/

The reason this code doesn't work is because you initialize the tabs widget twice:

$(function() {
    $( "#tabs" ).tabs(); //initialize tabs without specifying selected.
    $( "#tabs" ).tabs({ selected: 2 }); //doesn't work
});

Either do this:

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

or this:

$(function() {
    $( "#tabs" ).tabs();
    $( "#tabs" ).tabs( "option", "active", 2 );
});
于 2013-08-26T14:53:52.040 回答