<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
window.onload=function () {
var oPx=document.getElementById('insert');
var oTab=document.getElementById('tb1');
var oId=oTab.tBodies[0].rows.length;
oPx.onclick=function () {
var array=[];
for(var i=0;i<oTab.tBodies[0].rows.length;i++)
{
array[i]=oTab.tBodies[0].rows[i];
}
function paixu(tr1,tr2){
var n1=parseInt(tr1.cells[0].innerHTML);
var n2=parseInt(tr2.cells[0].innerHTML);
return n1-n2;
}
array.sort(paixu);
//alert(array[0]);
for(i=0;i<array.length;i++){
oTab.tBodies[0].appendChild(array[i]);
}
}
}
</script>
</head>
<body>
<input id="insert" type="button" value="排序">
<table id="tb1" border="1" cellspacing="0" style="width: 300px">
<thead>
<td>id</td>
<td>姓名</td>
<td>性别</td>
<td>操作</td>
</thead>
<tbody>
<tr>
<td>4</td>
<td>张三</td>
<td>男</td>
<td><a href="#">删除</a></td>
</tr>
<tr>
<td>3</td>
<td>李四</td>
<td>男</td>
<td><a href="#">删除</a></td>
</tr>
<tr>
<td>1</td>
<td>王二</td>
<td>男</td>
<td><a href="javascript:;">删除</a></td>
</tr>
<tr>
<td>2</td>
<td>尹五</td>
<td>女</td>
<td><a href="#">删除</a></td>
</tr>
</tbody>
</table>
</body>
</html>
最后修改:2020 年 10 月 27 日
© 允许规范转载