I have code like that:
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);
}
};
it works fine in FF, Chrome & Opera (it displays 1开发者_JAVA百科0x10 table with 30px width&height rows). In IE nothing happens. I check in firebug lite and it is in HTML section, inside BODY tag but i see nothing. Whats wrong?
It needs a few tweaks:
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 needs a <tbody>
in most cases, and wont' display empty cells, so it needs a space in there.
精彩评论