javascript 控制 table tr display block 显示模式时,只对第一个单元格有效

(本文来自 http://www.wilson-loo.com/wordpress/archives/140)

有一个简单的 table:

noteinfo_title  wilsol LOCAL - Opera

<table >
 <tr >
 <th>编号</th>
 <th>类型</th>
 <th>详细</th>
 <th>创建时间</th>
 <th>修改时间</th>
 <th>操作</th>
 </tr>
 
 <tr>
 <td>5</th>
 <td>TECH</th>
 <td>测试内容</th>
 <td>2014−01−10 16:56:31</th>
 <td>−−</th>
 <td>修改 删除</th>
 </tr>
 
 <tr id="id_dync" style="display:none">
 <td colspan=6>
 <div id=xxxx >测试内容</div>
 </td>
 </tr>
 
</table>

希望通过 javascript 控制 第三 行的 tr 隐显状态:

var tr_modifing = document.getElementById( "id_dync" );
tr_modifing.style.display = "block";

这种将 style.display 设置成 block 后, 会出现 只对第一个单元格 td 有效的情况:

noteinfo_title  wilsol LOCAL - Opera_2

原因是 将 tr.style.display = “block” 后, 该 tr 就不是普通的 【表格】之【行】了, 而就像普通的 div 一样普通的块, 所以下面的 

<td colspan=6 >

也会随着失效, 正确的做法是 

var tr_modifing = document.getElementById( "id_dync" );
tr_modifing.style.display = "table−row";

即 将 tr 的 显示模式设置为 【table-row】

原文地址:https://www.cnblogs.com/Wilson-Loo/p/3520078.html