如何逐个执行jquery代码?

fis*_*man 2 javascript jquery

如何逐个执行jquery代码?我想在完成工作时先做"功能1".然后做"功能2"......

谢谢.

<script type="text/javascript">
jQuery(document).ready(function(){
  $(document).ready(function(){ 
    //function 2, jqeury.ajax  
  });  
  $(document).ready(function(){ 
    //function 3, jqeury.json 
  });  
  $('#col').load("home.html"); 
    //function 4, jqeury.load
  });  
});
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
  //function 1,  a jquery slider plungin
});
</script>
Run Code Online (Sandbox Code Playgroud)

Joh*_*hnP 9

您不需要这么多文档就绪电话.一个就足够了

如果你的意思是你想要在收到来自你正在进行的AJAX调用的响应后调用每个方法,请将代码放入回调中;

$(document).ready(function(){
    one(); //call the initial method
});

function one(){
   $.get('url', {}, function(data){
      two(); //call two() on callback
   })
}

function two(){
   $.getJSON('url', {}, function(data){
       three(); //ditto
   })
}

function three(){
   $('#selector').load('url');
}
Run Code Online (Sandbox Code Playgroud)

文档

http://api.jquery.com/jQuery.get/

http://api.jquery.com/jQuery.getJSON/

http://api.jquery.com/load/