简体   繁体   English

创建具有多个级别的手风琴表

[英]Creating Accordion Table with Multiple Levels

I'm trying to create an accordion table with multiple headers that expand to reveal multiple expanding sub-headers. 我正在尝试创建一个具有多个标题的手风琴表,这些标题可以扩展以显示多个扩展子标题。

The HTML I have so far: 到目前为止,我拥有的HTML:

<tbody>

<tr class="header">
  <th colspan="2">Header</th>
</tr>

<tr>
  <td>Sub-Header1</td>
  <td>sub-info</td>
  <td>sub-info</td>
  <td>sub-info</td>
</tr>
<tr>
  <td>Sub-Header2</td>
  <td>sub-info</td>
  <td>sub-info</td>
  <td>sub-info</td>
</tr>

</tbody>

Here is the Javascript I have so far: 这是我到目前为止使用的Javascript:

<script>
$('.header').click(function(){
$(this).nextUntil('.header').slideToggle(100, function(){
    });
});
</script>

Everything seems to be working so far, EXCEPT, if I expand and collapse the sub-headers and then try to collapse the main header, the sub-headers open back up. 到目前为止,似乎一切工作正常,但如果我展开并折叠子标题,然后尝试折叠主标题,则子标题会重新打开。 I'm pretty sure it has something to do with the javascript, but I am unsure how to fix this or proceed. 我很确定它与javascript有关,但是我不确定如何解决此问题或继续进行。

If anyone can help me fix this code, or show me a new method to creating this accordion table, I would be very appreciative! 如果有人可以帮助我修复此代码,或向我展示创建此手风琴表的新方法,我将不胜感激!

Would something like this work, or is this what you are trying to achieve? 这样的事情行得通吗,或者这是您要达到的目标?
JSFiddle: http://jsfiddle.net/biz79/d02rm189/1/ JSFiddle: http : //jsfiddle.net/biz79/d02rm189/1/

Assuming the following structure: 假设具有以下结构:

Header

Subheader1 img some text link Subheader1 img一些文本链接

Subheader2 img some text link Subheader2 img一些文本链接

When you click on subheader1, the info hides or shows When you click on subheader2, the info hides or shows When you click on Header, the info hides or shows 当您单击subheader1时,信息会隐藏或显示当您单击subheader2时,信息会隐藏或显示当您单击Header时,信息会隐藏或显示

HTML HTML

<table>
<tbody>

<tr class='mainheader'>
    <th>Header</th>
</tr>

<tr>
  <td class="header">Sub-Header1
    <div class="hideMe">

      <img alt ="yellowpic"  src="https://dl.dropboxusercontent.com/u/2542034/colorPicks/yellow.png">
        <p>sub-info blah blah<p>
        <a>sub-info link</a>

    </div></td>
</tr>

<tr>
  <td class="header">Sub-Header2
  <div class="hideMe">
    sub-info<br>
    sub-info<br>
    sub-info
  </div></td>
</tr>

</tbody>
</table>

JS: JS:

$('.mainheader').on("click", function(){
  $(this).siblings()
         .slideToggle(100);
});

$('.header').on("click", function(){
  $(this).find('.hideMe')
         .slideToggle(100);
});

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

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