我有一个CSS风格
#mytbody > tr > th {
background-color: red;
}
和脚本
function myclick() {
$("#mytbody").append("<tr><td>1</td><td>1</td>/tr>");
}
这是我的html代码:
<table>
<thead>
<tr>
<td>head 1</td>
<td>head 2</td>
</tr>
</thead>
<tbody id="mytbody">
<tr>
<th>1</th>
<th>2</th>
</tr>
</tbody>
</table>
<button type="button" onclick="myclick()">button</button>
单击按钮添加的新行的css样式消失了。
为什么CSS不能用于添加行,以及如何保持CSS样式来添加新行?非常感谢你!
这是因为您的CSS仅用于th
标记。您还应该添加CSS td
:
#mytbody > tr > th,
#mytbody > tr > td {
background-color: red;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句