您好,我只在IE9中有问题
我有一个Javascript循环,它首先生成表
var TABLE = widget.body.getElementsByClassName('classroom')[0];
var TBODY = widget.createElement('tbody');
//generate rows & Cells, 10 x 10
var cID = 0;
for (var r=0; r<10; r++) {
var TR = widget.createElement('tr');
for (var c=0; c<10; c++) {
var TD = widget.createElement('td');
//TD.id="c"+cID;
TD.setAttribute("class",'c'+cID);
TD.setAttribute("id",'c'+cID);
TD.setAttribute("style","width:90px;");
TD.setAttribute("style","height:90px;");
cID++;
TR.appendChild(TD);
}
TBODY.appendChild(TR);
}
TABLE.appendChild(TBODY);哪个行得通?
然后调用另一个函数来填充表。
这只是一个代码片段,功能巨大!
var cell_class = cell.toString(); // it gets the cell from another loop say 'c1'
var TCell = widget.body.getElementsByClassName(cell_class)[0];
TCell.innerHTML="<a href='#'>image</a>"; // it fails at this point 'null or undefined'在HTML中,我有
<table id="table1" class="classroom">
<colgroup>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
<col width="90" height="70"/>
</colgroup>
</table>如果我将一个静态表格添加到HTML中,但我希望它是动态的,那么它就可以工作。
这在当前除IE9以外的所有浏览器中都有效
有人能帮上忙吗
发布于 2012-11-01 17:37:44
为什么不使用jQuery模板或handlebars (或任何其他模板库),有什么特殊的原因吗?来帮助你进行动态生成?
我认为IE的问题是,它不会在默认情况下创建TBODY元素,除非你在标记中有它。我认为其他浏览器会隐式创建该元素,如果它不存在的话。
尝试在标记中手动添加tbody元素。
https://stackoverflow.com/questions/13174219
复制相似问题