zoukankan      html  css  js  c++  java
  • 【JavaScript】JavaScript学习 五 JavaScript 注释

    JavaScript 注释可用于增强代码的可读性。

    JavaScript 注释

    可以添加注释来对 JavaScript 进行解释,或者提高其可读性。

    单行淖⑹鸵?// 开始。

    本例用单行注释来解释代码:

    <script type="text/javascript">
    // 这行代码输出标题:
    document.write("<h1>This is a header</h1>");
    // 这行代码输出段落:
    document.write("<p>This is a paragraph</p>");
    document.write("<p>This is another paragraph</p>");
    </script>

    TIY

    JavaScript 多行注释

    多行注释以 /* 开头,以 */ 结尾。

    本例使用多行注释来解释代码:

    <script type="text/javascript">
    /*
    下面的代码将输出
    一个标题和两个段落
    */
    document.write("<h1>This is a header</h1>");
    document.write("<p>This is a paragraph</p>");
    document.write("<p>This is another paragraph</p>");
    </script>

    TIY

    使用注释来防止执行

    在本例中,我们用注释来阻止一行代码的执行:

    <script type="text/javascript">
    document.write("<h1>This is a header</h1>");
    document.write("<p>This is a paragraph</p>");
    //document.write("<p>This is another paragraph</p>");
    </script>

    TIY

    在本例中,我们用注释来阻止若干行代码的执行:

    <script type="text/javascript">
    /*
    document.write("<h1>This is a header</h1>");
    document.write("<p>This is a paragraph</p>");
    document.write("<p>This is another paragraph</p>");
    */
    </script>

    TIY

    在行末使用注释

    在本例中,注释放置在语句的行末:

    <script type="text/javascript">
    document.write("Hello"); // 输出 "Hello" 
    document.write("World"); // 输出 "World" 
    </script>
  • 相关阅读:
    8-12-COMPETITION
    The Rotation Game(IDA*算法)
    Largest Rectangle in a Histogram(DP)
    Top ShooterHDU2863&&继续xxx定律HDU3784
    NYOJ 536 开心的mdd(DP)
    POJ1328 Radar Installation 图形转化 贪心 排序
    cout:格式算子与保留精度
    POJ 2109 Power of Cryptography二分+大数相乘和pow为什么可以直接过的原因
    字符串交换函数
    纪念一次失败的暴力 统计回文字串
  • 原文地址:https://www.cnblogs.com/cuishao1985/p/1525834.html
Copyright © 2011-2022 走看看