用tbody代替div 解决 table tr的隐藏问题

有如下需求,需要控制一个table内几个tr的显示问题。一开始想的方法是在这几个要显示的tr外面套一个div,利用div的display:none属性来解决。 但是后来发现div和tr嵌套的时候会有问题。例如,如果我的html页面是这样的源码:

Html代码:

 <head>
</head>
<body>
<table>
<div id="borrowAccountDiv_CJ" style="display:none;" mce_style="display:none;">
<tr>
<td>借方帐号:</td>
</tr>
<tr>
<td><input type="text" id="borrowAcount" name="borrowAcount" style="width:200px;" dataType="MoneyRequire" msg="借方帐号不能够为空,且必须为数字!"onclick="this.select()"/><fontcolorfontcolor="#FF0000"> *</font></td>
</tr>
</div>
</table>
</body>
<head>
</head>
<body>
<table>
<div id="borrowAccountDiv_CJ" style="display:none;" mce_style="display:none;">
<tr>
<td>借方帐号:</td>
</tr>
<tr>
<td><input type="text" id="borrowAcount" name="borrowAcount" style="width:200px;" dataType="MoneyRequire" msg="借方帐号不能够为空,且必须为数字!"onclick="this.select()"/><fontcolorfontcolor="#FF0000"> *</font></td>
</tr>
</div>
</table>
</body>

那么打开这个html页面后,发现层还是会显示。

后来才发现,其实div和tr的相互嵌套是有问题。所以可以用tbody来代替实现。实现后的代码如下:

Html代码:

 <head>
</head>
<body>
<table>
<tbody id="borrowAccountDiv_CJ" style="display:none;" mce_style="display:none;">
<tr>
<td>借方帐号:</td>
</tr>
<tr>
<td><input type="text" id="borrowAcount" name="borrowAcount" style="width:200px;" dataType="MoneyRequire" msg="借方帐号不能够为空,且必须为数字!"onclick="this.select()"/><fontcolorfontcolor="#FF0000"> *</font></td>
</tr>
</tbody>
</table>
</body>
<head>
</head>
<body>
<table>
<tbody id="borrowAccountDiv_CJ" style="display:none;" mce_style="display:none;">
<tr>
<td>借方帐号:</td>
</tr>
<tr>
<td><input type="text" id="borrowAcount" name="borrowAcount" style="width:200px;" dataType="MoneyRequire" msg="借方帐号不能够为空,且必须为数字!"onclick="this.select()"/><fontcolorfontcolor="#FF0000"> *</font></td>
</tr>
</tbody>
</table>
</body>

转自:http://yafei.iteye.com/blog/743860

上一篇:增加定时检测linux占用内存,及时清理功能


下一篇:(转)增加定时检测linux占用内存,及时清理功能