JavaScript statements, comments and code blocks

JavaScript statements  
<html>
<body>

<script type="text/javascript">
document.write("<h1>这是标题</h1>");
document.write("<p>这是段落。</p>");
document.write("<p>这是另一个段落。</p>");
</script>

</body>
</html>

JavaScript code block
<html>
<body>

<script type="text/javascript">
	{
	document.write("<h1>这是标题</h1>");
	document.write("<p>这是段落。</p>");
	document.write("<p>这是另一个段落。</p>");
	}
</script>

</body>
</html>


 

JavaScript single-line comment
<html>
<body>

<script type="text/javascript">
// 这行代码输出标题:
document.write("<h1>这是标题</h1>");
// 这行代码输出段落:
document.write("<p>这是段落。</p>");
document.write("<p>这是另一个段落。</p>");
</script>

</body>
</html>


 

JavaScript multi-line comments
<html>
<body>

<script type="text/javascript">
/*
下面的代码将输出
一个标题和两个段落
*/
document.write("<h1>这是标题</h1>");
document.write("<p>这是段落。</p>");
document.write("<p>这是另一个段落。</p>");
</script>

</body>
</html>


 

Use single line comment to prevent execution
<html>
<body>

<script type="text/javascript">
document.write("<h1>这是标题</h1>");
document.write("<p>这是段落。</p>");
//document.write("<p>这是另一个段落。</p>");
</script>

</body>
</html>


 

Use multi-line comments to prevent execution
<html>
<body>

<script type="text/javascript">
/*
document.write("<h1>这是标题</h1>");
document.write("<p>这是段落。</p>");
document.write("<p>这是另一个段落。</p>");
*/
</script>

</body>
</html>


 

Reproduced in: https: //my.oschina.net/u/2552902/blog/543826

Guess you like

Origin blog.csdn.net/weixin_33774883/article/details/92326434