2017-08-16 181 views
0

我有一個函數,打開和(應)關閉一系列的div。 讓我們說它的'手風琴。打開關閉div與點擊

<div class="cat_table_header" onclick="show_hide_table(this);"> 

的問題是,這手風琴的第一個div開始總是可見的,我想,這開始封閉。 此外,如果我點擊它,不關閉,但如果我點擊另一個div它關閉並打開點擊的div。

有什麼建議嗎?

+0

這將是有益的,如果你能提供的jsfiddle鏈接:) – Manjunath

+0

已經這個答案幫我找到的JavaScript它: – Travelbaba

回答

0

這是JavaScript:

jQuery(document).ready(function() { 
    jQuery(".cat_table_container").hide(); 
    jQuery(".cat_table_container:first").show(); 
}); 

function show_hide_table (table) { 
    table = jQuery(table).parent().find(".cat_table_container"); 
    if (jQuery(table).is(":visible")) { 
     if (jQuery(table).parents(".cat_container").attr("class") != "cat_container cat_container_parent") { 
      if (jQuery(".cat_container_parent .cat_table_container").length > 0) 
       jQuery(table).hide(); 
     } 
    } 
    else { 
     jQuery(".cat_table_container").hide(); 
     jQuery(".cat_container_parent .cat_table_container").show(); 
     jQuery(table).show(); 
    } 
} 
' 

非常感謝