JavaScript的格式 javaScript:::::::

陈鸿才
2023-12-01

* JavaScript的格式:

1. JavaScript区分大小写;

2. JavaScript脚本程序须嵌入在HTML文件中;

3. JavaScript脚本程序中不能包含HTML标记代码;(双引号)

4. 每行写一条脚本语句;

5. 语句末尾可以加分号;

6. JavaScript脚本程序可以独立保存为一个外部文件,但其中不能包含<script></script>标签。

 

 

* JavaScript脚本程序的几种基本格式:

 1. <script>
                      document.write("Hello World!!!");
                  </script>

2. <script language="JavaScript">
                      document.write("Hello World!!!");
                  </script>

3. <script language="JavaScript" type="text/JavaScript">
                      document.write("Hello World!!!");
                  </script>

4. <script language="JavaScript1.2">
                      document.write("Hello World!!!");
                  </script>

5. <script src="hello.js"></script>注意:document.write(&quot;Hello World!!!&quot;); 必须保存为一个外部文件:hello.js

6. <script language="JavaScript">
                  <!--
                      document.write("Hello World!!!");
                  -->
                  </script>

7. 使用JavaScript协议:

<a href="JavaScript:alert(''Hello World!!!'')">请单击</a>

<a οnclick="alert(''Hello World!!!'')" href="#">请单击</a>

<a οnclick="alert(''Hello orld!!!'')" href="JavaScript://">请单击</a>

 

 

 类似资料: