问题描述
注:重写问题:我正在尝试编写各个函数调用的以下 outside :
>例子:
函数f1(){
做某事1
函数f2(){
做某事2
}
运行函数1
完成后
运行函数2
(请参阅下面的jsfiddles的注释)
问题是,箱子在同一时间加载。行为应该是,加载红色,完成后,加载绿色。
如果这不是jQuery中常见的方法,请告诉我,也许我只是追逐ghost ...
$(document).ready(function(){
function firstFunction(){
alert(this is第一个函数!);
secondFunction();
}
函数secondFunction(){
alert(this is the second function!);
}
firstFunction();
});
或者,如果您不希望每次拨打第一个电话时调用第二个函数,您可以简单地按顺序调用它们
p> firstFunction();
secondFunction();
这是因为它会等到 firstFunction
在它移动到 secondFunction
*Note: Re-writing question:
I am trying to write the following outside of the individual function calls:
example:
function f1(){ do something 1 } function f2(){ do something 2 } run function 1 when done run function 2
(See comments below for jsfiddles)
Problem is, the boxes load at the same time. Behavior SHOULD be, load red, when done, load green.
If this isn't a common method in jQuery, let me know, maybe I'm just chasing a ghost...
You could simply call the second function at the end of the first.
$(document).ready(function() {
function firstFunction(){
alert("this is the first function!");
secondFunction();
}
function secondFunction(){
alert("this is the second function!");
}
firstFunction();
});
Alternatively, if you do not wish to call the second function every time you call the first, you could simply call them sequentially
firstFunction();
secondFunction();
This works because it will wait until firstFunction
is done before it moves on to secondFunction
fiddle
这篇关于jquery,如何在另一个函数结束后立即运行一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!