2020年3月4日 星期三

JavaScript 重點筆記

Tag 與位置


<html>
  <head>
    <script type="text/javascript">  // 放在 head 會比放在 body 先執行

    </script>
  </head>

  <body>
  </body>
</html>  


<html>
  <head>
  </head>
  <body>
    <script type="text/javascript">// 要取得 body 中元素,就放在 body 中

    </script>
  </body>

</html>

外部 JavaScript


HTML 檔:
<html>
  <head>
    <script src="demo.js" type="text/javascript">  // 副檔名是 .js

    </script>
  </head>

  <body>
  </body>
</html>

demo.js 檔:
alert ( " This is an alert box ! " )  // 不用寫 script Tag

輸出


document.write ( " Hello World ! " )
document.write ( " <h1> Hello World ! </h1>" )

註解

單行:// This is a comment.
多行:/*This is a comment. */


沒有留言:

張貼留言