2009-12-21 78 views
0

我無法隱藏一些div的內容,以僞標籤設置 - 我的代碼是在http://rudderlive.bito.org.nz/employment_dev2.aspjQuery的 - 在隱藏選項卡的內容選擇問題

標籤1至標籤2工作正常,但移動標籤2到標籤3不隱藏標籤2的div,並且從標籤3移回標籤1不會隱藏標籤2或3個div。

我的代碼如下 - 但它與HTML一起觀看(在上述網頁)時,更有意義......

$('ul.tabNav a').click(function() { 
    var curChildIndex = $(this).parent().prevAll().length + 1; 
    $(this).parent().parent().children('.current').removeClass('current'); 
    $(this).parent().addClass('current'); 
    $('div.tabContainer').children('.current').fadeOut('fast',function() { 
     $(this).removeClass('current'); 
     $('div.tabContainer').children('div:nth-child('+curChildIndex+')').fadeIn('normal',function() { 
     $(this).addClass('current'); 
     }); 
    }); 
    return false; 
}); 

回答

0

此代碼的工作(檢查與螢火蟲)。 $(this)似乎不適用於您的回調。

$("ul.tabNav a").click(function() 
{ 
    var curChildIndex = $(this).parent().prevAll().length; 

    $(this).parent().siblings().removeClass("current"); 
    $(this).parent().addClass("current"); 

    var tabContent = $(this).parents("ul.tabNav:first").next(".tabContainer").children(".current"); 
    tabContent.fadeOut("fast", function() 
    { 
     //console.log($(this)); --> returns the instance of the window 

     tabContent.removeClass("current"); 
     var newTabContent = tabContent.parent().children("div:eq("+ curChildIndex +")"); 

     newTabContent.fadeIn("fast", function() 
     { 
      newTabContent.addClass("current"); 
     }); 
    }); 

    return false; 
}); 
+0

感謝堆 - 比我的代碼好得多(除了事實上它也可以)!Bruce – TomBaine 2009-12-21 21:48:08

1

有什麼錯把current類新的可見內容。 所以你可以試試這個腳本。

$('div.tabContainer') 
    .children('.current') 
    .removeClass('current') // put here 
    .fadeOut('fast',function() { 

    // $(this).removeClass('current'); remove from here 

    $('div.tabContainer') 
     .children('div:nth-child('+curChildIndex+')') 
     .addClass('current') // put here 
     .fadeIn('normal',function() { 
     // $(this).addClass('current'); remove from here 
     }); 
    }); 

希望這將有助於

+0

謝謝 - 這真是太棒了 – TomBaine 2009-12-21 21:47:29

相關問題