ajax removeclass,jQuery addClass/removeClass after ajax success

博主遇到一个挑战,即在用户勾选或取消复选框后,通过Ajax提交表单并更新行的状态。问题在于淡入淡出效果导致整个行被移除,而不是仅仅改变类。尝试了两种方法,但都无法成功实现仅添加和移除'updated'类而不影响其他样式。寻求社区的帮助以解决这个问题。
摘要由CSDN通过智能技术生成

I've got an ajax form submission working well but I'd like to add a "success" class to indicate to the user that the request was completed when the user checked or unchecked a box. I've tried a few things so far:

$(".box").change(function() {

var id=$(this).val();

var dataString = "id=" + id + "&crudtype=myapp";

var clickedObj = $(this).parent().parent();

$.ajax( {

type: "POST",

url: "/myphppage",

data: dataString,

cache: false,

success: function() {

var oldClass = clickedObj.attr("class");

clickedObj.fadeIn(1400, function() {

clickedObj.removeClass(oldClass);

clickedObj.addClass("updated");

});

clickedObj.fadeOut(1400, function() {

clickedObj.removeClass("updated");

clickedObj.addClass(oldClass);

});

}

});

});

That one does indeed apply the "updated" class but the fadeOut actually removes the entire row of data (parent().parent() is the tag that I'm targeting.)

$(".box").change(function() {

var id=$(this).val();

var dataString = "id=" + id + "&crudtype=myapp";

var clickedObj = $(this).parent().parent();

$.ajax( {

type: "POST",

url: "/myphppage",

data: dataString,

cache: false,

success: function() {

var oldClass = clickedObj.attr("class");

clickedObj.removeClass(oldClass);

clickedObj.addClass("updated", 1000);

clickedObj.removeClass("updated", 1000);

clickedObj.addClass("updated");

}

});

});

I also tried this, but all that happens is that it (evidently) removes the existing class, adds the new one, and then does the same thing in reverse immediately so the new class is never seen. It appears that the 1000 delay is ignored despite the fact that I'm running jQueryUI on this site.

Thanks to anyone who can help!

EDIT: Adding in HTML code:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值