<html>
<body>
<table id="tableData" border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>$100</td>
</tr>
<tr>
<td>2</td>
<td>$200</td>
</tr>
<tr>
<td>3</td>
<td>$300</td>
</tr>
<tr>
<td>4</td>
<td>$400</td>
</tr>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
function SortTb()
{
var tb = $("#tableData tbody").find("tr");
var total = tb.length;
//外层循环,共要进行arr.length次求最大值操作
for (var i = 0; i < total; i++)
{
//内层循环,找到第i大的元素,并将其和第i个元素交换
for (var j = i; j < total ; j++)
{
$(tb).eq(j).insertBefore($(tb).eq(i));
$(tb).eq(i).insertAfter($(tb).eq(j));
}
}
return;
}
SortTb()
</script>
</body>
</html>