我有一些表结构:
<tr class="row-2"><tr>
<tr class="row-3">..<tr>
<tr class="row-4">..<tr>
<tr class="row-5">..<tr>
<tr class="row-6">..<tr>
<tr class="row-7"><tr>
<tr class="row-8">..<tr>
<tr class="row-9">..<tr>
<tr class="row-10">..<tr>
<tr class="row-11">..<tr>
...etc
对于此示例,具有“row-2”和“row-7”类的 TR 是扩展子行的父产品链接。
<script>
$(function() {
$('tr.parent')
.css("cursor","pointer")
.css("color","red")
.attr("title","Click to expand/collapse")
.click(function(){
$(this).siblings('.child-'+this.id).toggle();
});
$('tr[@class^=child-]').hide().children('td');
});
</script>
行 -3...-6 是第 2 行的孩子,第 -8 ...-11 行是第 7 行的孩子
如何找到第 2 行、第 7 行等,然后添加第二类“父”和 ID 相似类(id="row-2"、id="row-7" 等)?我还需要在第 2行和第 7 行之间的每个TR类中添加等于前一个父行。归根结底,我需要这样的东西:
<tr class="row-2 parent" id="row-2"><tr>
<tr class="row-3 child-row2">..<tr>
<tr class="row-4 child-row2">..<tr>
<tr class="row-5 child-row2">..<tr>
<tr class="row-6 child-row2">..<tr>
<tr class="row-7 parent" id="row-7"><tr>
<tr class="row-8 child-row7">..<tr>
<tr class="row-9 child-row7">..<tr>
<tr class="row-10 child-row7">..<tr>
<tr class="row-11 child-row7">..<tr>
..etc