例如:
<tr>
<td> <h6 id="id0" name="name" > 123</h6> </td>
</tr>
<tr>
<td> <h6 id="id1" name="name" > 456</h6> </td>
</tr>
用JS 實現後,調換位置。
<table id="tb"><tr>
<td> <h6 id="id0" name="name"> 123</h6> </td>
</tr>
<tr>
<td> <h6 id="id1" name="name"> 456</h6> </td>
</tr>
<tr>
<td> <h6 id="id2" name="name"> 789</h6> </td>
</tr>
<tr>
<td> <h6 id="id3" name="name"> 100</h6> </td>
</tr>
</table>
<script>
var tb=document.getElementById('tb'),rows = tb.rows, trs = [];
for (i in rows) trs[i] = rows[i];
console.log(trs);
trs.sort(function (a, b) {
//降序,升序是a在前面
return parseInt(b.cells[0].getElementsByTagName('h6')[0].innerHTML.replace(/\s/g, ''))
- parseInt(a.cells[0].getElementsByTagName('h6')[0].innerHTML.replace(/\s/g, ''))
});
for (i in trs) tb.appendChild(trs[i]);
</script>