[英]IE9 Javascript generated table
嗨,我只有在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之外,這在當前所有瀏覽器中均有效
誰能幫忙
有什么特殊的原因為什么您不使用jQuery模板或把手(或其他與此相關的模板庫)來幫助您進行動態生成?
我認為IE的問題是,除非您在標記中包含它,否則默認情況下它不會創建TBODY元素。 我認為其他瀏覽器會隱式創建該元素(如果不存在)。
嘗試在標記中手動添加tbody元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.