注释代码一般有两种方法:
- 单行注释
- 多行注释
单行注释
单行注释以"//"开头,到改行的末尾结束。下面是 单行注释实例:
<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> 继续阅读与本文标签相同的文章
下一篇 :
未来明星语言Julia或成Python劲敌
-
他让我国芯片研究停滞13年,还骗走11亿研发资金,现状如何?
2026-05-14栏目: 教程
-
健乐教学机器人可开展的教学实训内容
2026-05-14栏目: 教程
-
5G套餐曝光遭“吐槽”,iphone11受追捧,导致苹果11销量比较高
2026-05-14栏目: 教程
-
为什么修电脑的叫自己不要杀毒和清理垃圾?
2026-05-14栏目: 教程
-
当水乡建筑遇上机器人,成就乌镇又一网红景点
2026-05-14栏目: 教程
