Calling a function from one JavaScript file which requires another

前端 未结 2 1935
执笔经年
执笔经年 2021-01-17 19:55

I am trying to call a function written in one JavaScript file from another JavaScript file. I have the following code, but it doesn\'t work:

My HTML file



        
2条回答
  •  爱一瞬间的悲伤
    2021-01-17 20:37

    Try changing the order

    
    
    
    

    Because you call js2(); inside js1.js, so the script js2.js should be executed before.

    In your case, i think it should still work without changing orders like this because you call js2(); inside a function. When this script is executed:

    function js1()
    {
       alert("Hello from js1");
       js2();
    }
    

    Even the js2.js is not executed yet, but you do not actually call js2(); at this time.

    Just try it to see if it works.

提交回复
热议问题