js table 排序 自己写的
<script type = "text/javascript">
$(function() {
$("th").click(function() {
var aTrs = new Array();
var $oTable = $("#tb1Sort");
var thIndex = $oTable.find("th").index($(this));
$oTable.find("tbody td:nth-child(" + (thIndex + 1) + ")").each(function() {
aTrs.push($(this).text());
});
aTrs.sort(compareTRs);
for (var i = 0; i <= aTrs.length; i++) {
$oTable.find("tbody td:nth-child(" + (thIndex + 1) + ")").eq(i).text(aTrs[i]);
}
});
});
function compareTRs(a, b) {
return a.localeCompare(b);
}
</script>
</head>
<body>
<table border="1" id="tb1Sort">
<thead>
<tr><th>Last Name</th><th>My god</th><th>no Name</th></tr>
</thead>
<tbody>
<tr>
<td>looping</td> <td>Smith</td> <td>ing</td>
</tr>
<tr>
<td>Smith</td> <td>girl</td> <td>learing</td>
</tr>
<tr>
<td>Teacher</td> <td>Teacher</td> <td>englis</td>
</tr>
<tr>
<td>girl</td> <td>Smith</td> <td>just</td>
</tr>
<tr>
<td>boy</td> <td>OMG</td> <td>to</td>
</tr>
<tr>
<td>Jn3</td> <td>boy</td> <td>tell</td>
</tr>
<tr>
<td>OMG</td> <td>n5</td> <td>you</td>
</tr>
<tr>
<td>n5</td> <td>girl</td> <td>something</td>
</tr>
</tbody>
</table>
</body>
$(function() {
$("th").click(function() {
var aTrs = new Array();
var $oTable = $("#tb1Sort");
var thIndex = $oTable.find("th").index($(this));
$oTable.find("tbody td:nth-child(" + (thIndex + 1) + ")").each(function() {
aTrs.push($(this).text());
});
aTrs.sort(compareTRs);
for (var i = 0; i <= aTrs.length; i++) {
$oTable.find("tbody td:nth-child(" + (thIndex + 1) + ")").eq(i).text(aTrs[i]);
}
});
});
function compareTRs(a, b) {
return a.localeCompare(b);
}
</script>
</head>
<body>
<table border="1" id="tb1Sort">
<thead>
<tr><th>Last Name</th><th>My god</th><th>no Name</th></tr>
</thead>
<tbody>
<tr>
<td>looping</td> <td>Smith</td> <td>ing</td>
</tr>
<tr>
<td>Smith</td> <td>girl</td> <td>learing</td>
</tr>
<tr>
<td>Teacher</td> <td>Teacher</td> <td>englis</td>
</tr>
<tr>
<td>girl</td> <td>Smith</td> <td>just</td>
</tr>
<tr>
<td>boy</td> <td>OMG</td> <td>to</td>
</tr>
<tr>
<td>Jn3</td> <td>boy</td> <td>tell</td>
</tr>
<tr>
<td>OMG</td> <td>n5</td> <td>you</td>
</tr>
<tr>
<td>n5</td> <td>girl</td> <td>something</td>
</tr>
</tbody>
</table>
</body>