您可以尝试在tr上使用prevAll()和nextAll()。如果没有返回结果,则表示所述tr是第一个子或最后一个子。
$(".up,.down").click(function(){
var row = $(this).parents("tr:first");
if ($(this).is(".up")) {
row.insertBefore(row.prev());
if(row.prevAll().length == 0){
//you just moved a row to the top. this is where you disable the button
row.find('.up').find('input').attr('disabled','true');
//the row that was the top before had its up disabled, enable it
row.prev().find('.up').find('input').removeAttr('disabled');
}
} else {
row.insertAfter(row.next());
//do same kind of thing here with nextAll
}
});