在选择的jQuery UI选项卡上显示/隐藏某个div

问题描述:

我有一个工作的jQuery UI标签,结构类似这样:

I have a working jQuery UI tabs, the structure is similarly like this:

<script>
    $( "#tabs" ).tabs();
</script>

<div id="tabs">
  <ul>
    <li><a href="#tabs-1"></a>Tab 1</li>
    <li><a href="#tabs-2"></a>Tab 2</li>
  </ul>
  <div id="tabs-1">
    <!-- content of tab 1 -->
  </div>
  <div id="tabs-2">
    <!-- content of tab 2 -->
  </div>
</div>
<div id="extra">
    <!-- some contents here -->
</div>

现在,我想在选择 Tab 2 时隐藏div ,而在选择标签1 时显示。我不太明白jQuery UI标签上的事件。

Now, I wanted to hide the div extra when Tab 2 is selected, while showing it when Tab 1 is selected. I can't quite understand the event thing on jQuery UI tabs.

activate event

$("#tabs").tabs({
    activate: function (e, ui) {
        $('#extra').toggle(ui.newPanel.is('#tabs-1'))
    }
});

演示:小提琴