Codice PHP:
<script>
var Table=(function( data ){
if( typeof data !== 'object' ){
return false;
}
if( typeof data.cols === 'undefined' || !data.cols ){
return false;
}
if( typeof data.rows === 'undefined' || !data.rows ){
return false;
}
if( data.rows * data.cols > 10000 ){
alert( 'maximum cell exceeded' );
return false;
}
var _d=document;
var _dbg=_d.getElementById('debug');
var _tt = _d.createElement('table');
var _th = _d.createElement('thead');
var _tb = _d.createElement('tbody');
var _tf = _d.createElement('tfoot');
_tt.appendChild( _th );
_tt.appendChild( _tb );
_tt.appendChild( _tf );
_tt.style.width = '100%';
_tt.style.height = '100%';
var _w=_d.createElement('div');
_w.style.width = '500px';
_w.style.height = '230px';
_w.style.overflow = 'auto';
_w.style.border = '3px outset #ddd';
_w.appendChild( _tt );
var _r = _tb.insertRow(-1);
var _c = _r.insertCell( 0 );
_c.innerHTML = 0;
var colsLeft = data.cols-1;
var cellNum = 1;
(function createFirstRow(){
if( colsLeft <= 20 ){
var reminder = colsLeft;
for( i=0; i<reminder; i++ ){
_ctmp = _c.cloneNode( true );
_r.appendChild( _ctmp );
_ctmp.innerHTML = cellNum;
cellNum++;
colsLeft--;
}
var rowsLeft = data.rows-1;
(function addRows( ){
if( rowsLeft <= 20 ){
var reminder = rowsLeft;
for( i=0; i<reminder; i++ ){
_nr = _r.cloneNode( true );
_nr.style.backgroundColor = (rowsLeft % 2) ? '#ddd' : '#fff';
_nr.style.color = (rowsLeft % 2) ? '#000' : '#666';
_tb.appendChild( _nr );
_cells=_nr.getElementsByTagName('td');
for(var n in _cells){
_cells[n].innerHTML = cellNum;
cellNum++;
}
rowsLeft--;
}
}
else{
for( i=0; i<20; i++ ){
_nr = _r.cloneNode( true );
_nr.style.backgroundColor = (rowsLeft % 2) ? '#ddd' : '#fff';
_nr.style.color = (rowsLeft % 2) ? '#000' : '#666';
_tb.appendChild( _nr );
_cells=_nr.getElementsByTagName('td');
for(var n in _cells){
_cells[n].innerHTML = cellNum;
cellNum++;
}
rowsLeft--;
}
window.setTimeout( arguments.callee , 25 );
}
})( );
}
else{
for( i=0; i<20; i++ ){
_ctmp = _c.cloneNode( true );
_r.appendChild( _ctmp );
_ctmp.innerHTML = cellNum;
cellNum++;
colsLeft--;
}
window.setTimeout( arguments.callee , 25 );
}
})( );
return{
appendTo:(function( elem ){
elem.appendChild( _w );
})
}
});
var t1 = new Table( {cols:100,rows:100} );
t1.appendTo( document.getElementsByTagName('body')[0] );
</script>