您好,欢迎访问一九零五行业门户网

javascript 注释代码的几种方法(图文教程)

为了程序/代码的易读性,基本上每一种编程语言都有注释的功能,javascript也不例外,javascript注释代码有多种形式,本文章向大家介绍javascript注释代码的两种方法,需要的朋友可以参考一下
javascript注释代码一般有两种方法:
单行注释
多行注释
javascript单行注释
单行注释以//开头,到改行的末尾结束。下面是javascript单行注释实例:
<html> <head> <title>javascript单行注释</title> <script language="javascript"> <!-- // the first alert is below alert("an alert triggered by javascript!"); // here is the second alert alert("a second message appears!"); // --> </script> </head> <body> </body> </html>
javascript多行注释
多行注释以 /* 开始,以 */ 结尾。下面的例子使用多行注释来解释代码:
<html> <head> <title>javascript多行注释</title> <script language="javascript"> <!-- /* 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 javascript!"); alert("a second message appears!"); // --> </script> </head> <body> </body> </html>
如何解决浏览器不支持javascript
应用注释符号验证浏览器是否支持javascript脚本功能.
如果用户不能确定浏览器是否支持javascript脚本,那么可以应用html提供的注释符号进行验证。html注释符号是以“<--”开始以“-->”结束的。如果在此注释符号内编写javascript脚本,对于不支持javascript的浏览器,将会把编写的javascript脚本作为注释处理。
使用javascript脚本在页面中输出一个字符串,将javascript脚本编写在html注释中,如果浏览器支持javascript将输出此字符串,如果不支持将不输出此字符串,代码如下:
<html> <head> <title>hide scripts using comments.</title> <script language="javascript" type="text/javascript"> <!-- document.write("您的浏览器支持javascript脚本!"); //--> </script> </head> <body> page content here... </body> </html>
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
js中object对象的原型概念基础(内容详细,一目了然)
12条写出高质量js代码的方法(教你写出高品质代码)
详细介绍在js中map和foreach的区别
以上就是javascript 注释代码的几种方法(图文教程)的详细内容。
其它类似信息

推荐信息