JQuery基于类折叠表格单元格

Bri*_*ard 3 html jquery

嗨,我的菜单有一个表格结构,我需要能够从level2折叠/展开菜单,以便所有level3单元格可见.我的HTML是这样的:

<table>
<tr><td class="level1"><a href="abc.html">First Item</a></td></tr>
<tr><td class="level2"><a href="def.html">SecondItem</a></td></tr>
<tr><td class="level3"><a href="ghi.html">Third Item</a></td></tr>
<tr><td class="level3"><a href="jkl.html">Fourth Item</a></td></tr>
<tr><td class="level3"><a href="mno.html">Fifth Item</a></td></tr>
<tr><td class="level2"><a href="pqr.html">Sixth Item</a></td></tr>
<tr><td class="level2"><a href="stu.html">Seventh Item</a></td></tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我怎么样,当我按下level2项目时,我只会折叠/展开level2后推送的level3项目?我只想为level2做这个,而不是为1级做.

RoT*_*oRa 5

您是否考虑过为菜单使用嵌套列表?它不仅使您的任务更容易,而且是"更好"的结构(关键字:无表格布局).