External JavaScript Not Running, does not write to document

前端 未结 4 1402
我寻月下人不归
我寻月下人不归 2021-01-13 17:14

I\'m trying to use an external JavaScript file in order to write \"Hello World\" into a HTML page.

However for some reason it does not work, I tried the same functio

4条回答
  •  执笔经年
    2021-01-13 17:49

    In general, you want to place your JavaScript at the bottom of the page because it will normally reduce the display time of your page. You can find libraries imported in the header sometimes, but either way you need to declare your functions before you use them.

    http://www.w3schools.com/js/js_whereto.asp

    index.html

    
    
    
    
      
      
      
    
    
    
    
      

    Hi

    hello.js

    function externalFunction() {
      document.getElementById("external").innerHTML = "Hello World!!!";
    }
    

    Plunker here.

    Hope this helps.

提交回复
热议问题