Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery淡入淡出,删除,然后执行下一步_Jquery_Jquery Ui - Fatal编程技术网

jquery淡入淡出,删除,然后执行下一步

jquery淡入淡出,删除,然后执行下一步,jquery,jquery-ui,Jquery,Jquery Ui,我有一张桌子,我想 将行淡出,然后将其删除(这样可以正常工作) 删除后,我将汇总所有列并更新总数 那个钻头坏了。它是在删除行之前进行的汇总 如何使此运行同步 $("#tr_invoice_" + id).fadeOut("slow", function() { $("#tr_invoice_" + id).remove(); tot = $("[name^=amount]").sum(); confirm("got tot: " + tot);

我有一张桌子,我想 将行淡出,然后将其删除(这样可以正常工作)

删除后,我将汇总所有列并更新总数 那个钻头坏了。它是在删除行之前进行的汇总

如何使此运行同步

$("#tr_invoice_" + id).fadeOut("slow", function() { 
  $("#tr_invoice_" + id).remove();      
  tot = $("[name^=amount]").sum(); 
  confirm("got tot: " + tot);                           
});
在阅读了@pulses comment之后,我改变了周围的情况,并手动从总和中删除了“已删除行”的数量,但这开始使总数少于当前行数量的2倍

因此,我将其还原并将确认更改为$(“#tag”).html(tot)。它开始工作正常,所以我不确定这是我的语法错误,还是确认与之有关,但不管怎样,它现在都工作正常


鉴于此,我应该删除这个问题,还是保持原样?

从您发布的摘录中我可以看出,您的代码似乎是正确的:

您将在动画之后删除该元素,然后重新查询所有必要的元素并对其求和

唯一的解释是,该元素没有被删除,并且它仍然以某种方式被您的查询捕获。尝试使用Firebug确认该元素确实已删除


另外,请尝试使
$(“[name^=amount]”)更精确一点。目前,它可以匹配很多节点,甚至可能是表外的一些节点。

尝试在删除后设置延迟:

$("#tr_invoice_" + id).fadeOut("slow", function() { 
  $("#tr_invoice_" + id).remove();      
  setTimeout(function(){
     tot = $("[name^=amount]").sum(); 
     confirm("got tot: " + tot);                           
  },100);
});
换成这个

$("#tr_invoice_" + id).fadeOut("slow", function() { 
  $("#tr_invoice_" + id).remove(function(){
    tot = $("[name^=amount]").sum(); 
    confirm("got tot: " + tot);
  });
});

如果下面的代码仍然返回相同的总数,那么您肯定是按照DR的建议添加了一个rogue元素

tot = $("[name^=amount]").not('#' + $(this).attr('id')).sum();

@pulse—在这种情况下,它工作正常,我应该更改sum函数,以考虑jquery对象表行仍然存在。或者从jquery对象中删除表行容易吗?(对jquery来说还是新手)我认为pulse是不对的,因为您正在重新查询必要的元素,以便考虑更新的DOM状态。