forma correcta (filas & cols & la innerText al azar se ajusta dinámicamente por u ...) esta manera no es prolly la más corta, pero a través el más rápido para construir una mesa. también es una mesa llena con la culata en T y lleno de texto al azar
1.Utilice Javascript nativo (no ralentizar jQuery)
2. (function() {})() ejecuta el código antes de cuerpo es de carga
3.And no tienen problemas con otras variables fuera de la función
4.and aprobar el documento de modo u tienen las variables más cortas
5.there es una manera de acortar la función utilizando el clon nodo ... bu t es más lento y quizás no sea compatible con todos los navegadores
6.createDocumentFragment() para crear los tr's. si tienes muchas filas, esto ayuda mucho a construir el DOM más rápido.
(function (d) {
var rows = 10,
cols = 3,
t = d.createElement('table'),
the = d.createElement('thead'),
tb = d.createElement('tbody'),
tr = d.createElement('tr');
t.style.width = "100%";
t.style.borderCollapse = 'collapse';
for (var a = 0; a < cols; a++) {
var th = d.createElement('th');
th.innerText = Math.round(Math.random() * 100);
tr.appendChild(th);
};
the.appendChild(tr);
var f = d.createDocumentFragment();
for (var a = 0; a < rows; a++) {
var tr = d.createElement('tr');
for (var b = 0; b < cols; b++) {
var td = d.createElement('td');
td.innerText = Math.round(Math.random() * 100);
tr.appendChild(td);
}
f.appendChild(tr);
}
tb.appendChild(f);
t.appendChild(the);
t.appendChild(tb);
window.onload = function() {
d.body.appendChild(t)
};
})(document)
También puede colocar su secuencia de comandos a continuación * theBlah * y funcionará sin un * onload * oyente. – RobG