How to add JavaScript to a HTML Document?

How to add JavaScript to a HTML Document?

add JavaScript HTML的圖片搜尋結果

Internal script

<script>
... JavaScript code goes here
</script>
Example:
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Simple Page</title>
    <script >
      var n = 10;
      alert(n);
    </script>
  </head>
  <body>
  </body>
</html>

External scripts

<script src="my_script.js"></script>
Example:
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Simple Page</title>
    <script src="my_script.js"></script>
  </head>
  <body>
  </body>
</html>
my_script.js

var n = 10;
alert(n);

Comments