表格如何排序表格并基于值(标记),自动选择具有最低值的单选按钮
<html>
<title></title>
<head></head>
<body>
<table id="one" class="tabl" cellspacing="0" >
<tbody>
<tr class="row">
<td><input class="dep" type="radio" name="depart"></td>
<td><a class="marks">500</a></td>
</tr>
<tr class="row">
<td><input class="dep" type="radio" name="depart"></td>
<td><a class="marks">200</a></td>
</tr>
<tr class="row">
<td><input class="dep" type="radio" name="depart"></td>
<td><a class="marks">300</a></td>
</tr>
<tr class="row">
<td><input class="dep" type="radio" name="depart"></td>
<td><a class="marks">400</a></td>
</tr>
</tbody>
</table>
</body>
</html>
答案 0 :(得分:0)
$(function(){
var table = $('#one');
var sortMarks = function(a,b)
{
var aVal = Number($(a).find('a.marks').text()),
bVal = Number($(b).find('a.marks').text());
return aVal > bVal ? 1 : -1;
};
table.find('tr').sort(sortMarks).appendTo(table); // sort
table.find('tr:first input.dep').attr('checked', 'checked'); // select first row (lowest)
});