简体   繁体   English

如何禁用Jquery UI中除活动选项卡之外的其他选项卡。 使用下一步和PRev按钮

[英]How disable other tabs except active tab in Jquery UI. Using Next and PRev Button

I am building a example of switching tab with Next and Previous buttons. 我正在构建一个使用“下一个”和“上一个”按钮切换选项卡的示例。 and you cannot click the other tab when you are in a tab. 并且当您位于标签中时,您无法单击其他标签。 I can build this next and previous function with jquery UI js/css because it has so many online tutorial for it. 我可以使用jquery UI js / css构建此下一个和上一个功能,因为它具有许多在线教程。 but i am having problem to disable other tabs when you jumping other tabs. 但是我在跳其他标签时禁用其他标签时遇到问题。 i try to add and remove class for other tab but fail. 我尝试为其他选项卡添加和删除类,但失败。

this is my code: 这是我的代码:

<div id="tabs">
<ul>
    <li>
        <a href="#tabs-1">Page 1</a>

    </li>
    <li>
        <a href="#tabs-2" class="ui-state-disabled">Page 2</a>

    </li>
    <li>
        <a href="#tabs-3" class="ui-state-disabled">Page 3</a>

    </li>
</ul>
<div id="tabs-1">
    <p>Test content 1</p>
    <a href="#" class="btn-primary btnNext" style="color:white;">Next Tab</a>
</div>
<div id="tabs-2">

    <p>Test content 2</p>
    <a href="#" class="btn-primary btnPrev" style="color:white;">Previous Tab</a>
    <a href="#" class="btn-primary btnNext" style="color:white;">Next Tab</a>
</div>
<div id="tabs-3">
    <p>Test content 3</p>
    <a href="#" class="btn-primary btnPrev" style="color:white;">Previous Tab</a>
</div>
</div>

This is my Script 这是我的剧本

 $("#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);
});

my goal is when you click the next button from page 1 , then you will go to page 2 but the tab of page 2 will become not disable (i am using ui-state-disabled to disable those tab for the first entry of this page) , and the tab of page 1 will be disable, and also tab of page 3 keep disable still. 我的目标是,当您单击页面1上的下一个按钮时,您将转到页面2,但页面2的选项卡将变得不禁用(我正在使用ui-state-disabled禁用该选项卡,以用于此页面的第一项),第1页的标签将被禁用,第3页的标签也将保持禁用状态。

I have tried the code below but its not working because it disable the whole div but not the tab 我已经尝试了下面的代码,但由于它禁用了整个div但未禁用制表符,因此无法正常工作

 $("#tabs" + 1).removeClass("ui-state-disabled");
    $("#tabs").addClass("ui-state-disabled");

i have coding logic problem XD 我有编码逻辑问题XD

Need to seek answer here. 需要在这里寻求答案。

I think You want like this: 我想你想要这样:

HTML HTML

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Tab1</a></li>
        <li><a href="#tabs-2">Tab2</a></li>
        <li><a href="#tabs-3">Tab3</a></li>
    </ul>
    <div id="tabs-1">
        <p>pag1</p>
    </div>
    <div id="tabs-2">
        <p>page2</p>
    </div>
    <div id="tabs-3">
        <p>page3</p>
    </div>
</div>

JS JS

$(document).ready(function() {

    $(function() {

        var $tabs = $('#tabs').tabs({
            disabled: [0, 1, 2]
        });

        $(".ui-tabs-panel").each(function(i) {

            var totalSize = $(".ui-tabs-panel").size() - 1;

            if (i != totalSize) {
                next = i + 2;
                $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
            }

            if (i != 0) {
                prev = i;
                $(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
            }

        });

        $('.next-tab, .prev-tab').click(function() {
            var tabIndex = $(this).attr("rel");
            $tabs.tabs('enable', tabIndex)
                .tabs('select', tabIndex)
                .tabs("option","disabled", [0, 1, 2]);
            return false;
        });


    });

});

CSS: CSS:

/* Prev / Next */
a.mover { background-color: #FBE863; color: #957D31; padding: 6px 12px; position: absolute; font-weight: bold; text-decoration: none; }
.next-tab { border-left: 5px solid #fff; border-bottom: 5px solid #fff; top: 250px; right: 0;}
.prev-tab { border-right: 5px solid #fff; border-bottom: 5px solid #fff; top: 250px; left: 0;}

Demo 演示

 <script>
   $(document).ready(function() {

    $(function() {

        var $tabs = $('#tabs').tabs({
            disabled: [0, 1, 2,3]
        });

        $(".ui-tabs-panel").each(function(i) {

            var totalSize = $(".ui-tabs-panel").size() - 1;

            if (i != totalSize) {
                next = i + 2;
                $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
            }

            if (i != 0) {
                prev = i;
                $(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
            }

        });

        $('.next-tab, .prev-tab').click(function() {
            var tabIndex = $(this).attr("rel");
            $tabs.tabs('enable', tabIndex)
                .tabs('select', tabIndex)
                .tabs("option","disabled", [0, 1, 2,3]);
            return false;
        });


    });

});
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM