<
script language
=
"
javascript
"
>
var sortType = 1 ;
function sortByCol(colNum)
... {
var parNode=document.getElementById("listTable"); //定位到table
for(var i=0;i<parNode.rows.length-1;i++)
...{
for(var n=1;n<parNode.rows.length-1-i;n++)
...{
var ifrom=parNode.rows.length-n;
var ito=parNode.rows.length-n-1;
if(sortType==1)
...{
if(parNode.rows[ifrom].cells[colNum].childNodes[0].data>parNode.rows[ito].cells[colNum].childNodes[0].data)
parNode.moveRow(ifrom,ito);
}else...{
if(parNode.rows[ifrom].cells[colNum].childNodes[0].data<parNode.rows[ito].cells[colNum].childNodes[0].data)
parNode.moveRow(ifrom,ito);
}
}
}
sortType=0-sortType;
}
</ script >
< table id = " listTable " width = " 100% " border = " 1 " cellpadding = " 0 " cellspacing = " 1 " >
< tr >
< th onclick = " sortByCol(0); " > 序号 </ th >
< th onclick = " sortByCol(1); " > 姓名 </ th >
< th onclick = " sortByCol(2); " > 年龄 </ th >
< th onclick = " sortByCol(3); " > 班级 </ th >
< th onclick = " sortByCol(4); " > 成绩 </ th ></ tr >
< tr >< td > 1 </ td >< td > ZXE </ td >< td > 56 </ td >< td > 1 </ td >< td > 13 </ td ></ tr >
< tr >< td > 2 </ td >< td > SCHB </ td >< td > 34 </ td >< td > 3 </ td >< td > 23 </ td ></ tr >
< tr >< td > 3 </ td >< td > WE </ td >< td > 23 </ td >< td > 3 </ td >< td > 34 </ td ></ tr >
< tr >< td > 4 </ td >< td > SQD </ td >< td > 34 </ td >< td > 2 </ td >< td > 76 </ td ></ tr >
< tr >< td > 5 </ td >< td > EDE </ td >< td > 67 </ td >< td > 1 </ td >< td > 34 </ td ></ tr >
< tr >< td > 6 </ td >< td > BD </ td >< td > 32 </ td >< td > 2 </ td >< td > 78 </ td ></ tr >
< tr >< td > 7 </ td >< td > AA </ td >< td > 23 </ td >< td > 1 </ td >< td > 34 </ td ></ tr >
</ table >
var sortType = 1 ;
function sortByCol(colNum)
... {
var parNode=document.getElementById("listTable"); //定位到table
for(var i=0;i<parNode.rows.length-1;i++)
...{
for(var n=1;n<parNode.rows.length-1-i;n++)
...{
var ifrom=parNode.rows.length-n;
var ito=parNode.rows.length-n-1;
if(sortType==1)
...{
if(parNode.rows[ifrom].cells[colNum].childNodes[0].data>parNode.rows[ito].cells[colNum].childNodes[0].data)
parNode.moveRow(ifrom,ito);
}else...{
if(parNode.rows[ifrom].cells[colNum].childNodes[0].data<parNode.rows[ito].cells[colNum].childNodes[0].data)
parNode.moveRow(ifrom,ito);
}
}
}
sortType=0-sortType;
}
</ script >
< table id = " listTable " width = " 100% " border = " 1 " cellpadding = " 0 " cellspacing = " 1 " >
< tr >
< th onclick = " sortByCol(0); " > 序号 </ th >
< th onclick = " sortByCol(1); " > 姓名 </ th >
< th onclick = " sortByCol(2); " > 年龄 </ th >
< th onclick = " sortByCol(3); " > 班级 </ th >
< th onclick = " sortByCol(4); " > 成绩 </ th ></ tr >
< tr >< td > 1 </ td >< td > ZXE </ td >< td > 56 </ td >< td > 1 </ td >< td > 13 </ td ></ tr >
< tr >< td > 2 </ td >< td > SCHB </ td >< td > 34 </ td >< td > 3 </ td >< td > 23 </ td ></ tr >
< tr >< td > 3 </ td >< td > WE </ td >< td > 23 </ td >< td > 3 </ td >< td > 34 </ td ></ tr >
< tr >< td > 4 </ td >< td > SQD </ td >< td > 34 </ td >< td > 2 </ td >< td > 76 </ td ></ tr >
< tr >< td > 5 </ td >< td > EDE </ td >< td > 67 </ td >< td > 1 </ td >< td > 34 </ td ></ tr >
< tr >< td > 6 </ td >< td > BD </ td >< td > 32 </ td >< td > 2 </ td >< td > 78 </ td ></ tr >
< tr >< td > 7 </ td >< td > AA </ td >< td > 23 </ td >< td > 1 </ td >< td > 34 </ td ></ tr >
</ table >