如何在Javascript中等待行的执行?

如何在Javascript中等待行的执行?,javascript,jquery,Javascript,Jquery,.delay我试过了,但不起作用。如果您使用的是jQuery UI,您应该可以添加一个回调作为第四个参数 $("#div_id").click(function() { $(this).effect("shake", { times:3 }, 300); // Here I want wait that the div_id can complete its shake alert('hello'); } 见: 您需要使用回调。 $(this).effect("sh

.delay我试过了,但不起作用。

如果您使用的是jQuery UI,您应该可以添加一个回调作为第四个参数

$("#div_id").click(function() {
    $(this).effect("shake", { times:3 }, 300);
    // Here I want wait that the div_id can complete its shake
    alert('hello');
  }
见:

您需要使用回调。
$(this).effect("shake", { times:3 }, 300, function() {

    // this will alert once the animation has completed
    alert('hello');
});
$("#div_id").click(function() {
    $(this).effect("shake", { times:3 }, 300, function(){
        alert('hello');
    });
}
$(this).effect("shake", { times:3 }, 300, function() {
   alert('hello');
});