如何在Javascript中等待执行行?

时间:2011-04-26 12:43:37

标签: javascript jquery

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

.delay我试过但它没有用。

3 个答案:

答案 0 :(得分:2)

$(this).effect("shake", { times:3 }, 300, function() {

    // this will alert once the animation has completed
    alert('hello');
});

答案 1 :(得分:0)

如果你正在使用jQuery UI,你应该只能添加一个回调作为第四个参数。

请参阅:http://jqueryui.com/demos/effect/

$("#div_id").click(function() {
    $(this).effect("shake", { times:3 }, 300, function(){
        alert('hello');
    });
}

答案 2 :(得分:0)

$(this).effect("shake", { times:3 }, 300, function() {
   alert('hello');
});