Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $when.then()执行的jQuery序列_Javascript_Jquery - Fatal编程技术网

Javascript $when.then()执行的jQuery序列

Javascript $when.then()执行的jQuery序列,javascript,jquery,Javascript,Jquery,我试图按特定的顺序执行函数,但在理解$.when()时遇到了问题 函数x(){ def=$.Deferred(); $.when(def).then(console.log(def.state()); } x() 然后需要回调,因此您应该创建一个wrap函数: function x() { def = $.Deferred(); $.when(def).then(function(){ console.log(def.state()) }); } x(); 然后需要回调,

我试图按特定的顺序执行函数,但在理解
$.when()
时遇到了问题

函数x(){
def=$.Deferred();
$.when(def).then(console.log(def.state());
}
x()

然后
需要回调,因此您应该创建一个wrap函数:

function x() {
  def = $.Deferred();
  $.when(def).then(function(){
    console.log(def.state())
  });
}
x();

然后
需要回调,因此您应该创建一个wrap函数:

function x() {
  def = $.Deferred();
  $.when(def).then(function(){
    console.log(def.state())
  });
}
x();

第一:您应该解决您的
差异
。第二:您应该将函数传递给
,然后传递给
方法

函数x(){
def=$.Deferred().resolve();
$.when(def).then(函数(){
console.log(def.state());
});
}
x()

首先:您应该解决您的
差异问题。第二:您应该将函数传递给
,然后传递给
方法

函数x(){
def=$.Deferred().resolve();
$.when(def).then(函数(){
console.log(def.state());
});
}
x()

解释为什么可能有用。解释为什么可能有用。