如何在jquery-ui 1.9中以编程方式更改选项卡? [英] How to change tabs programmatically in jquery-ui 1.9?

查看:153
本文介绍了如何在jquery-ui 1.9中以编程方式更改选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery-ui 1.9以编程方式更改标签?

How do you change tabs programmatically with jquery-ui 1.9?

注意:发布答案,因为我花了4次以上搜索在stackoverflow上找到正确的答案。它出现在1.9中,API已更改,在早期版本中,您将使用 $(#tabs)。tabs(select,2)

NOTE: Posting the answer because it took me more than 4 searches to find the right answer on stackoverflow. It appears in 1.9 the API has changed, in earlier versions, you would use $("#tabs").tabs("select", 2).

<script>
    $(document).ready(function() {
      $("#tabs").tabs();

      // assume you want to change to the 3rd tab after 3 seconds
      setTimeout(function() {
         // ???
      }, 3000);
    });
</script>

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Tab 1</a></li>
        <li><a href="#tabs-2">Tab 2</a></li>
        <li><a href="#tabs-3">Tab 3</a></li>
    </ul>

    <div id="tabs-1"><p>Container 1</p></div>
    <div id="tabs-2"><p>Container 2</p></div>
    <div id="tabs-3"><p>Container 3</p></div>
</div>


推荐答案

选择方法自1.9以来已弃用,并且<在1.10 中删除了一个href =http://jqueryui.com/upgrade-guide/1.10/#re​​moved-select-method-use-active-option>。请改用 active 选项。

示例( jsfiddle 也提供):

<script>
    $(document).ready(function() {
      $("#tabs").tabs();

      // assume you want to change to the 3rd tab after 3 seconds
      setTimeout(function() {
          $("#tabs").tabs("option", "active", 2);
      }, 3000);
    });
</script>

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Tab 1</a></li>
        <li><a href="#tabs-2">Tab 2</a></li>
        <li><a href="#tabs-3">Tab 3</a></li>
    </ul>

    <div id="tabs-1"><p>Container 1</p></div>
    <div id="tabs-2"><p>Container 2</p></div>
    <div id="tabs-3"><p>Container 3</p></div>
</div>

这篇关于如何在jquery-ui 1.9中以编程方式更改选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆