Jquery function is not working due to $(document).ready

前端 未结 4 463
花落未央
花落未央 2021-01-22 18:48

we have two js fie , test-1.js , test-2.js.




        
4条回答
  •  春和景丽
    2021-01-22 19:16

    Adding this second answer because you changed the order to be correct, but then also changed the contents of the scripts. Since they both contain a $(document).ready(function() {...}); where you create the functions, this means the functions you create only exist in the scope of that function, e.g.

    function foo() { 
      return 1;
    }
    
    $(document).ready(function() {
      // this is a new scope, functions created here will not be accessible outside of it.
      function bar() {
        return 2;
      }
    });
    
    foo(); // 1
    bar(); // Error: undefined is not a function

提交回复
热议问题