<html>
<head> <script> function order() { var it=event.srcElement; var table=it; var i,j,k; var t1,t2; if(it.tagName=="TH"){ i=it.cellIndex; it.title=it.title=="asc"?"desc":"asc"; while(table.tagName!="TABLE")table=table.parentElement; if(table.rows.length<3)return true; for(j=1;j<table.rows.length;j++){ for(k=j+1;k<table.rows.length;k++){ if(it.title=="asc"?parseFloat(table.rows[k].cells[i].innerText)<parseFloat(table.rows[j].cells[i].innerText):parseFloat(table.rows[k].cells[i].innerText)>parseFloat(table.rows[j].cells[i].innerText)) table.rows[j].swapNode(table.rows[k]); } } } } </script> </head> <body> <table border="1">
<thead onclick="order()" style="cursor:hand;"> <th>Item 1</th><th>Item 2</th><th>Item 3</th><th>Item 4</th> </thead> <tr><td>12.3</td><td>423</td><td>86.83</td><td>1.213</td></tr> <tr><td>2</td><td>434</td><td>5.334</td><td>.234</td></tr> <tr><td>33</td><td>43</td><td>5.223</td><td>8.73</td></tr> <tr><td>21.3</td><td>234</td><td>52.34</td><td>.666</td></tr> <tr><td>33.4</td><td>59</td><td>67.2</td><td>.426</td></tr> </table> </body>
</html> |
|