用js自动生成表格如何设置td的class属性

问题描述:

这里是js的部分关键代码
[code="java"]
var table=document.getElementById("table1");
var newRow=table.insertRow(table.rows.length);

newRow.setAttribute("align","center");

var newCell=newRow.insertCell(0);
newCell.height = "24";

newCell.innerHTML=i;

newCell=newRow.insertCell(1);
newCell.setAttribute("class","td_3");
newCell.innerHTML='jboss培训';[/code]

但是,出来的效果没有td_3的效果,我在网上找了很久,也没找到如何正确设置自动生成的表格的td属性。

当然,我保证td_3在css里面是正确的,我直接写的时候是有效果的。

有知道怎么设置的吗?谢谢了

newCell.className = "td_3" 试试
如果不行,你把td_3的css贴出来看看

newCell.setAttribute("className","td_3");