Java



           

Сортировка таблицы средствами JavaScript - часть 9


function createTable( cStart, cType, cSize, cChange ) { var tabbd = document.getElementById( "tablebody" );

if( !tabbd ) { var table = document.getElementById( "table" ); var tbody = document.createElement( "tbody" ); tbody.id = "tablebody"; table.appendChild( tbody ); tabbd = document.getElementById( "tablebody" ); }

while( tabbd.hasChildNodes() ) { var tmp = tabbd.childNodes[ 0 ]; tabbd.removeChild( tmp ); }

for( var counter = cStart; eval( counter + cType + cSize ); eval( "counter" + cChange ) ) { var tr = document.createElement( "tr" );

var td = document.createElement( "td" ); var tdtxt = document.createTextNode( txt[ counter ].years ); td.appendChild( tdtxt ); tr.appendChild( td ); td = document.createElement( "td" ); tdtxt = document.createTextNode( txt[ counter ].books ); td.appendChild( tdtxt ); tr.appendChild( td ); td = document.createElement( "td" ); tdtxt = document.createTextNode( txt[ counter ].authors ); td.appendChild( tdtxt ); tr.appendChild( td ); tabbd.appendChild( tr ); } }

function allocator( arg ) {

if( flag == arg ) { if( sorted == "up" ) { createTable( 0, "<", txt.length, "++" ); sorted = "down"; } else { createTable( txt.length - 1, ">=", 0, "--" ); sorted = "up"; } return; }

quickSort( 0, txt.length - 1, arg ); createTable( 0, "<", txt.length, "++" ); flag = arg; }

</script> </head> <body>

<table border="1" id="table"> <tr> <td><a href="javascript:allocator( 'yweight' )">Год</a></td> <td><a href="javascript:allocator( 'bweight' )">Книга</a></td> <td><a href="javascript:allocator( 'aweight' )">Автор</a></td> </tr> <tbody id="tablebody"></tbody> </table>




Содержание  Назад  Вперед