单击按钮时更改活动选项卡

发布于 2024-12-01 15:06:27 字数 321 浏览 7 评论 0原文

我有两个由 jquery-ui 生成的选项卡。我在 Tab1 中执行某些操作,然后单击按钮,就会有一个 AJAX 调用在 Tab2 中显示结果。

所以我想更改按钮单击时的活动选项卡(ajax调用完成后)。我可以这样做吗?

我创建了一个 jsFiddle here


我尝试了 onclick='$("#tabs -2").trigger("点击") '> 但它没有做任何事情。

I have two tabs generated by jquery-ui. I do something in the Tab1 and on a button click, there is an AJAX call which displays the results in Tab2.

So I want to change the active tab on button click ( after the ajax call finishes ). Can I do so?

I've created a jsFiddle here


I tried onclick='$("#tabs-2").trigger("click")
'>
but it didn't do anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一桥轻雨一伞开 2024-12-08 15:06:27

作为信息(以防有人稍后偶然发现这一点并在 select 方法上遇到错误) - 在 jQuery-UI 1.9+ 中, select 方法已被弃用。

http://jqueryui.com/upgrade-guide/1.9/#deprecated-select-method)

使用option方法,示例:

$("#tabs").tabs("option", "active", 2);

As info (in case someone stumbles upon this later and gets an error on the select method) - In jQuery-UI 1.9+, the select method was deprecated.

(http://jqueryui.com/upgrade-guide/1.9/#deprecated-select-method)

Use the option method, example:

$("#tabs").tabs("option", "active", 2);
随风而去 2024-12-08 15:06:27

使用 onclick='$("#tabs").tabs( "select", "tabs-2" )'

http://jqueryui.com/demos/tabs/#method-select

Use onclick='$("#tabs").tabs( "select", "tabs-2" )'

http://jqueryui.com/demos/tabs/#method-select

很酷不放纵 2024-12-08 15:06:27

js小提琴

http://jsfiddle.net/maheshvemuri/M7Fdu/

< strong>这是代码的 JS 部分:

$(document) .ready(function() {
    $("#tabs").tabs(); 
    $(".btnNext").click(function () {
            $( "#tabs" ).tabs( "option", "active", $("#tabs").tabs('option', 'active')+1 );
        });
        $(".btnPrev").click(function () {
            $( "#tabs" ).tabs( "option", "active", $("#tabs").tabs('option', 'active')-1 );
        });
});

以下是要添加到选项卡 div 中的“a href”标签

示例:

<div id="tabs-1">
<a class="myButton btnNext" style="color:white;">Next Tab</a>
</div>
<div id="tabs-2">
<a class="myButton btnPrev" style="color:white;">Previous Tab</a>
<a class="myButton btnNext" style="color:white;">Next Tab</a>
</div>
<div id="tabs-3">
<a class="myButton btnPrev" style="color:white;">Previous Tab</a>
</div>

js fiddle

http://jsfiddle.net/maheshvemuri/M7Fdu/

Here is JS part of the code:

$(document) .ready(function() {
    $("#tabs").tabs(); 
    $(".btnNext").click(function () {
            $( "#tabs" ).tabs( "option", "active", $("#tabs").tabs('option', 'active')+1 );
        });
        $(".btnPrev").click(function () {
            $( "#tabs" ).tabs( "option", "active", $("#tabs").tabs('option', 'active')-1 );
        });
});

Here are the "a href" tags to be added in your tabs div

Example:

<div id="tabs-1">
<a class="myButton btnNext" style="color:white;">Next Tab</a>
</div>
<div id="tabs-2">
<a class="myButton btnPrev" style="color:white;">Previous Tab</a>
<a class="myButton btnNext" style="color:white;">Next Tab</a>
</div>
<div id="tabs-3">
<a class="myButton btnPrev" style="color:white;">Previous Tab</a>
</div>
你是我的挚爱i 2024-12-08 15:06:27

您必须对“li”内的“a”进行触发器调用,而不是像完成的那样直接调用选项卡“div”。

<div id="tabs">     
    <ul>
        <li><a id="lnk1" href="#tabs-1">tab1</a></li>   
        <li><a id="lnk2" href="#tabs-2">tab2</a></li>             
    </ul>    
    <div id="tabs-1">
     <button type="button" id="clicktab2" onclick='$("#lnk2").trigger("click");'>
       go to tab2
     </button>
    </div>
    <div id="tabs-2">
     tab2 content 
    </div>
</div>

示例:

http://jsfiddle.net/Tf9sc/152/

You have to make the trigger call to "a" inside the "li", not direct to the tab "div" like it's done.

<div id="tabs">     
    <ul>
        <li><a id="lnk1" href="#tabs-1">tab1</a></li>   
        <li><a id="lnk2" href="#tabs-2">tab2</a></li>             
    </ul>    
    <div id="tabs-1">
     <button type="button" id="clicktab2" onclick='$("#lnk2").trigger("click");'>
       go to tab2
     </button>
    </div>
    <div id="tabs-2">
     tab2 content 
    </div>
</div>

Example:

http://jsfiddle.net/Tf9sc/152/

厌味 2024-12-08 15:06:27

您也可以尝试

$(window).load(function(){
   $('#tabs-2').trigger('click');
});

这样做,因为您无法在就绪模式下触发调用 tabs() 。 document.ready 早于 window.load 执行。

Also you can try

$(window).load(function(){
   $('#tabs-2').trigger('click');
});

that's because you cannot trigger call the tabs() in ready mode. document.ready is executed earlier than window.load.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文