我相信那里有许多“表格排序器”插件,但这个简短的代码可以实现您正在寻找的东西
脚本
var alphas = 'abcdefghijklmnopqrstuvwxyz';
$(document).ready(function () {
var tmp = '';
for (var x = 0; x < 26; x++) tmp += '<a href="#">' + alphas[x].toUpperCase() + '</a> ';
$('#table_filter').append(tmp);
$('#table_filter a').click(function () {
if ($(this).attr('id') == 'show_all') {
$('#searchNames tbody tr').css('display', 'table-row');
$('#message').html('displaying all rows');
return false;
}
var alpha = $(this).html();
$('#searchNames tbody tr').hide().filter(function () {
var td = $('td:first', $(this));
return td.length && td.html() && new RegExp('^' + alpha + '.*$', 'i').test(td.html().toLowerCase());
}).css('display', 'table-row');
$('#message').html('displaying rows with "' + alpha + '"');
return false;
})
});
和标记
<div id="table_filter">
<a id="show_all" href="#">Show All</a>
</div>
<p id="message"></p>
<table class="table1" id="searchNames" style="width:500px;">
<thead>
<tr>
<th>CONTACT NAME</th>
<th>col 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>ssfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>asdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>apodf</td>
<td>Col2</td>
</tr>
<tr>
<td>opkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>lkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>nlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>qwdsdfsd</td>
<td>Col2</td>
</tr>
<tr>
<td>essfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>easdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>qapodf</td>
<td>Col2</td>
</tr>
<tr>
<td>oopkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>dlkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>snlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>vqwdsdfsd</td>
<td>Col2</td>
</tr>
<tr>
<td>ssfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>asdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>apodf</td>
<td>Col2</td>
</tr>
<tr>
<td>opkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>lkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>nlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>qwdsdfsd</td>
<td>Col2</td>
</tr>
<tr>
<td>essfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>easdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>qapodf</td>
<td>Col2</td>
</tr>
<tr>
<td>oopkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>dlkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>snlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>vqwdsdfsd</td>
<td>Col2</td>
</tr>
<tr>
<td>ssfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>asdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>apodf</td>
<td>Col2</td>
</tr>
<tr>
<td>opkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>lkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>nlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>qwdsdfsd</td>
<td>Col2</td>
</tr>
<tr>
<td>essfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>easdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>qapodf</td>
<td>Col2</td>
</tr>
<tr>
<td>oopkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>dlkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>snlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>vqwdsdfsd</td>
<td>Col2</td>
</tr>
<tr>
<td>ssfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>asdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>apodf</td>
<td>Col2</td>
</tr>
<tr>
<td>opkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>lkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>nlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>qwdsdfsd</td>
<td>Col2</td>
</tr>
<tr>
<td>essfjkn jkdsnf</td>
<td>Col2</td>
</tr>
<tr>
<td>easdl kln</td>
<td>Col2</td>
</tr>
<tr>
<td>qapodf</td>
<td>Col2</td>
</tr>
<tr>
<td>oopkpokj</td>
<td>Col2</td>
</tr>
<tr>
<td>dlkohasd</td>
<td>Col2</td>
</tr>
<tr>
<td>snlkcn</td>
<td>Col2</td>
</tr>
<tr>
<td>vqwdsdfsd</td>
<td>Col2</td>
</tr>
</tbody>
</table>
和 jsfiddle
http://jsfiddle.net/Khq9k/2/
更新
使其基于 4 过滤<td>
,替换
var td = $('td:first', $(this));
和
var td = $('td:nth-child(4)', $(this));