表格排序

<table id=downloadList border="1" width="100%" onclick="sortTable()">
  <tr>
    <td>AddCommonInfo.mxp</td>
    <td>MXP File</td>
    <td>2614</td>
    <td>2002-12-30 16:45:22,Fri</td>
  </tr>
  <tr>
    <td>addtemplateparam.mxp</td>
    <td>MXP File</td>
    <td>3100</td>
    <td>2002-12-5 13:28:24,Sun</td>
  </tr>
</table>
<script>
var curObj;
function sortTable() {
 var start=new Date()

var i;
var theRows=new Array();
for(i=0;i<downloadList.rows.length;i++) {
 theRows[i]=new Array(downloadList.rows[i].cells[0].innerText.toLowerCase(),downloadList.rows[i].outerHTML);
 }
theRows.sort(sortRows);
var str=''
for(i=0;i<theRows.length;i++) {
 str+=theRows[i][1];
 }
downloadList.outerHTML='<table id=downloadList border="1" width="100%">'+str+'</table>'
curObj=null;
alert(new Date()-start)
return ;
}

function sortRows(x,y) {

  if(x[0]>y[0]) return -1;
  else if(x[0]<y[0]) return 1;
  else return 0;

}
</script>

你可能感兴趣的:(sun)