我有一个带有替代颜色行的表格。
$("#contTbl tr:even").addClass("altBgr");
我有一个函数可以执行一些事务,并且在 AJAX 发布后删除了该行。
$(".clickMe").click(function() {
var trID = $(this).closest("tr").attr("id");
$.ajax({
url: "ajax.php",
type: "POST",
data: {
contID: trID
},
success: function(data){
$("#"+trID).remove();
}
});
});
我遇到的问题是当我删除一行时,其他行的颜色变得困惑...有没有办法在删除时以某种方式刷新它?
最佳答案
如何在点击时删除 class
并在成功检索时将其添加回来?
$(".clickMe").click(function() {
var trID = $(this).closest("tr").attr("id");
$.ajax({
url: "ajax.php",
type: "POST",
data: {
contID: trID
},
success: function(data){
$("#"+trID).remove();
$("#contTbl tr:even").removeClass("altBgr");
$("#contTbl tr:even").addClass("altBgr");
}
});
});
已编辑:根据我自己的评论
You can try putting both the removeClass() and addClass() in the success: and see if that eliminates the flicker
关于jquery - 重新排序替代颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7682166/