$('#div1').focus(函数(){ callAnotherFunction();
$(this).animate({});
}
我试图让 $(this).animate({});
在 callAnotherFunction();
完成后执行。目前,两者同时运行。我已经定时使用 delay(), setTimeout() 也无济于事。无论如何,这可以做到吗?
谢谢!
最佳答案
JavaScript 是单线程的,因此一次只能执行一个表达式。在您给出的示例中,$(this).animate({});
在 callAnotherFunction();
完成之前不会运行。
callAnotherFunction();
可能会在计时器或延迟上运行额外的代码,在这种情况下,你必须使用 $(this).animate({});
在超时时执行相同或更长的延迟。
关于javascript - 仅当特定事件完成时才执行的 jquery 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2546059/