1

このコードを継承したので、変更を加える必要があります。私は一連のタブを持っています:

<div id="Tabs">
    <ul>
        <li><a href="#divGen" id="lnkGeneral">General</a></li>
        <li><a href="#divA" id="lnkA">A</a></li>
        <li><a href="#divB" id="lnkB">B</a></li>
        <li><a href="#divC" id="lnkC">C</a></li>
    </ul>
</div>

これらは、ドロップダウンから選択した値に応じて、jqueryを使用して非表示/表示されます。

$("#divA").hide(); $("#divB").show(); $("#divC").hide();  
$("#lnkA").hide(); $("#lnkB").show(); $("#lnkC").hide();

最初のタブ(divGen)が常に表示されます。次のタブに移動するためのボタンを追加しているので、タブのリストをループして、表示される可能性のあるタブを判別する方法が必要です。タブは動的に表示されるため、ボタンを表示するかどうかと、押したときにどのタブに「回転」するかを決定する必要があります。私は運が悪かったので次のことを試みました:

var $tabs = $('#Tabs').tabs();  
var i, count = 0;  
for (i = 0; i < $tabs.tabs('length'); i++) {  
    if ($tabs.tabs(i).is('visible')) {  
        count++;  
    }  
}  

if (count > 1)) {  
    Display the button.  
}

私は何が欠けていますか?私はすべての例を調べましたが、解決策を見つけることができません。非表示/表示が原因で、表示テストが正しく行われていないことが原因だと思います。

前もって感謝します

4

2 に答える 2

4

デモ

if ( $('#Tabs ul li:visible').length > 1) ) {  
    //Display the button.  
}

アップデート

アンカータグを非表示にしている場合(あなたがそうであるように見えます)、使用する必要があるかもしれません

if ( $('#Tabs ul li a:visible').length > 1) ) {  
    //Display the button.  
}
于 2011-05-03T19:28:17.793 に答える
0

ボタンの表示/非表示の場合:

// if more than one tab is visible display the button  
if ($('#Tabs ul li a:visible').length > 1)) {  
       //Display the button.  
} else {  
       //Display the button.  
}

ボタンが呼び出す機能は次のとおりです。

function fnNextTab(div) {  
    var $tabs = $(div).tabs();
    var selected = $tabs.tabs('option', 'selected');
    var max = $tabs.tabs('length') - 1; // Zero based

    $(div + ' ul li a').each(function(i) {
        // if the tab is visible and 'after' the current tab select it
        if (($(this).is(':visible')) && (i > selected)) {
            $tabs.tabs("select", i);    // This selects the tab
            $tabs.tabs('load', i);      // This displays the tab
            return false;               // Done searching
        }

        if (i >= max) {
            // Goto the General (first) tab
            $tabs.tabs("select", 0);    // This selects the tab
            $tabs.tabs('load', 0);      // This displays the tab
        }
    });
}

この関数を別のページで使用できるように、'div' が呼び出しで渡されます。それぞれが異なるタブのコレクションを持ち、異なる名前になっています。

于 2011-05-05T17:29:02.007 に答える