jquery, how to run a function as soon as another function ends

前端 未结 6 1854
梦谈多话
梦谈多话 2021-01-12 18:58

*Note: Re-writing question:

I am trying to write the following outside of the individual function calls:

example:

function f1(){
         


        
6条回答
  •  梦毁少年i
    2021-01-12 19:21

    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();
    });
    

    fiddle

    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

提交回复
热议问题