注释代码一般有两种方法:

  1. 单行注释
  2. 多行注释

 

单行注释

单行注释以"//"开头,到改行的末尾结束。下面是 单行注释实例:

<html>
<head>
< > 单行注释</ >
<  language=\" \">
<!--
// The first alert is below
alert(\"An alert triggered by  !\");
// Here is the second alert
alert(\"A second message appears!\");
//  -->
</ >
</head>
<body>

</body>
</html>

 

多行注释

多行注释以 /* 开始,以 */ 结尾。下面的例子使用多行注释来解释代码:

<html>
<head>
< > 多行注释</ >
<  language=\" \">
<!--
/*
Below two alert() methods are used to
fire up two message boxes - note how the
second one fires after the OK button on the
first has been clicked
*/
alert(\"An alert triggered by  !\");
alert(\"A second message appears!\");
//  -->
</ >
</head>
<body>

</body>
</html>

 

如何解决浏览器不支持

应用注释符号验证浏览器是否支持 脚本功能.

如果用户不能确定浏览器是否支持 脚本,那么可以应用HTML提供的注释符号进行验证。HTML注释符号是以“<--”开始以“-->”结束的。如果在此注释符号内编写 脚本,对于不支持 的浏览器,将会把编写的 脚本作为注释处理。

使用 脚本在页面中输出一个字符串,将 脚本编写在HTML注释中,如果浏览器支持 将输出此字符串,如果不支持将不输出此字符串,代码如下:

<html>
<head>
< >Hide  s using comments.</ >
<  language=\" \" type=\"text/ \">
<!--
document.write(\"您的浏览器支持 脚本!\");
//-->
</ >
</head>
<body>
Page content here...
</body>
</html>
收藏 打印