2014-11-06 66 views
0

我试图用切换行设置表。jQuery切换表行

|-------------------------------------| 
| Time | Icon | Name | Toggle Button | 
|  |-----------------------------| 
|  | Description (toggled)  | 
|-------------------------------------| 

<table> 
    <tr> 
     <td rowspan="2" class="time-block">Time</td> 
     <td>Icon</td> 
     <td>Name</td> 
     <td><a href="#" class="toggle-button">Toggle Button</a></td> 
    </tr> 
    <tr class="description"> 
     <td colspan="3">Description</td> 
    </tr> 
</table> 

$('.toggle-button').click(function(e){ 
    e.preventDefault(); 
    $(this).closest('tr').next('tr').toggle(); 
}); 

这jQuery不会触发以下tr,但是当它的布局被因的“时间” td细胞的rowspan属性杂乱无章。

我的目标是在函数中添加一行,将rowspan属性更改为'1'。

添加$(this).closest('tr td.time').attr('rowspan', '1')该功能不起作用。

任何帮助,非常感谢!

回答

1
$('.time-block').attr('rowspan',1); 
+0

这不起作用。另外,在这种情况下,我相信一个字符串和一个数字一样好。 http://api.jquery.com/attr/ – psorensen 2014-11-06 17:37:47

+1

这个工作对我来说 http://jsfiddle.net/uou32j17/ – 2014-11-06 17:40:11

+0

谢谢你。看到这个更新的小提琴看到的问题:基本上,表部分有很多迭代,所以'.closest()'是必要的。 http://jsfiddle.net/uou32j17/ – psorensen 2014-11-06 17:48:47