(使用jquery)我有以下功能
$(function() {
$('tr.parent')
.css("cursor","pointer")
.attr("title","Click to expand/collapse")
.click(function(){
$(this).siblings('.child-'+this.id).toggle();
});
$('tr[@class^=child-]').hide().children('td');
});
我有以下网页
<table>
<col style="width:40px;">
<col style="width:80px;">
<col style="width:150px;">
<col style="width:40px;">
<thead>
<tr>
<th>ID</th>
<th colspan="2">Name</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr class="parent" id="row123">
<td>123</td>
<td colspan="2">[+]Bill Gates</td>
<td>100</td>
</tr>
<tr class="child-row123">
<td> </td>
<td>2007-01-02</td>
<td>A short description</td>
<td>15</td>
</tr>
<tr class="child-row123">
<td> </td>
<td>2007-02-03</td>
<td>Another description</td>
<td>45</td>
</tr>
<tr class="child-row123">
<td> </td>
<td>2007-03-04</td>
<td>More Stuff</td>
<td>40</td>
</tr>
<tr class="parent" id="row456">
<td>456</td>
<td colspan="2">[+]Bill Brasky</td>
<td>50</td>
</tr>
<tr class="child-row456">
<td> </td>
<td>2007-01-02</td>
<td>A short description</td>
<td>10</td>
</tr>
</tbody>
</table>
期望的结果:
在可展开部分左侧带有“[+]”和“[-]”的文本之间进行更改,以表明它可以展开或压缩。