我正在尝试调用 2 个函数。第一个函数包含一个 jQuery 效果。第二个函数(在本例中是 jQuery 效果),但可能仅在第一个函数执行(并完成)时执行。有人可以帮我吗?谢谢!
狐狸示例:http://jsfiddle.net/fNH2u/1/
function hideSecond(){
$("#second").hide("slow");
}
$("#first").click(function(){
hideSecond();
$(this).hide("fast");
});
和 HTML:
<div id="first">
first
</div>
<div id="second">
second
</div>
我想调用的函数不仅仅是那个 jQuery 效果。这只是一个例子。将这两个功能放在一起并不是我真正想要的。
最佳答案
您需要在此处使用回调。
function hideSecond(callback){
$("#second").hide("slow", callback);
}
$("#first").click(function(){
hideSecond(function() {
$(this).hide("slow");
});
});
关于javascript - jQuery 等待直到函数被执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5657052/