JavaScript Tutorial/Language Basics/Comments

Материал из Web эксперт
Версия от 18:52, 25 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Hide scripts using comments

<html>
<head>
<title>Hide scripts using comments.</title>
<script language="javascript" type="text/javascript">
<!--
lines of JavaScript code here
...
//-->
</script>
</head>
<body>
Page content here...
</body>
</html>


Multiline comments

/* */ enables comments to span multiple lines.



<html>
<head>
<title>A Simple Page</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>


Single line comments

The // comment tag enables comments to be placed between the // and the end of the line.



<html>
<head>
<title>A Simple Page</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>