我有这样的代码:
var xPola = 10, //how many cols
yPola = 10, //how many cols
bokPola = 30, //size of cell
body = document.getElementsByTagName('body')[0];
var tablica = document.createElement('table');
body.appendChild(tablica);
for( var y = 0; y < yPola; y++ ) {
var rzad = document.createElement('tr');
tablica.appendChild(rzad);
for( var x = 0; x < xPola; x++ ) {
var pole = document.createElement('td');
pole.setAttribute('width', bokPola);
pole.setAttribute('height', bokPola);
rzad.appendChild(pole);
}
};
它适用于FF,Chrome和&amp; Opera(它显示10x10表,宽度为30px,高度为行)。在IE中没有任何反应。我检查了firebug lite,它在HTML部分,在BODY标签内,但我什么也看不见。怎么了?
答案 0 :(得分:2)
需要一些调整:
var xPola = 10, //how many cols
yPola = 10, //how many cols
bokPola = 30, //size of cell
body = document.getElementsByTagName('body')[0];
var tablica = document.createElement('table');
body.appendChild(tablica);
var tbody = document.createElement('tbody');
tablica.appendChild(tbody);
for( var y = 0; y < yPola; y++ ) {
var rzad = document.createElement('tr');
tbody.appendChild(rzad);
for( var x = 0; x < xPola; x++ ) {
var pole = document.createElement('td');
pole.innerHTML=' ';
pole.style.width = pole.style.height = bokPola;
rzad.appendChild(pole);
}
}
IE在大多数情况下需要<tbody>
,并且不会显示空单元格,所以它需要一个空格。