对我来说很好:
http://jsbin.com/awame3
$("a[title='Edit']").click(function(e){
e.preventDefault();
$(this).parent().prevAll("td").each(function(){
alert($(this).html());
});
});
更新特定单元格
$("a[title='Edit']").click(function(e){
e.preventDefault();
var cell = $(this).closest("tr").find("td:eq(0)").html("new values");
alert($(cell).html());
});
您可以将一个类应用于需要操作的任何单元格,并完全放弃对索引的寻址:
$(this).parent().siblings("td.editMe").html("new values");
获取单元格2-5
使用过滤器,您可以得到单元格2到5:
$(this).closest("tr").children("td:gt(0)").filter(":lt(5)");