将属性设置为动态生成的标签
我通过 JavaScript 将动态行添加到表中:
var cell1 = row.insertCell(0);
var element2 = document.createElement('input');
element2.value = "valueHere";
element2.type = "text";
cell1.appendChild(element2);
它在表中创建新行:
<tr>
<td>
<input type="text" value="valueHere">
</td>
</tr>
我想向 标记添加一个类。例如
I am adding dynamic row to table through JavaScript:
var cell1 = row.insertCell(0);
var element2 = document.createElement('input');
element2.value = "valueHere";
element2.type = "text";
cell1.appendChild(element2);
It creates new row in table:
<tr>
<td>
<input type="text" value="valueHere">
</td>
</tr>
I want to add a class to <td>
tag. e.g. <td class="styleClass">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置表格的
className
属性单元格(cell1
):You need to set the
className
property of the table cell (cell1
):将类别添加到单元格/TD
To add a class to a cell/TD