How to comment/uncomment in HTML code

前端 未结 11 1650
名媛妹妹
名媛妹妹 2020-12-28 13:39

Often while coding view templates in html, my habit of adding some helpful comments causes lots of time-consuming effort while testing.

Consider this code...

相关标签:
11条回答
  • 2020-12-28 13:58

    My view templates are generally .php files. This is what I would be using for now.

    <?php // Some comment here ?>
    

    The solution is quite similar to what @Robert suggested, works for me. Is not very clean I guess.

    0 讨论(0)
  • 2020-12-28 13:58

    No. Unless you find a tool that does what you described for you.

    0 讨论(0)
  • 2020-12-28 14:02

    you can try to replace --> with a different string say, #END# and do search and replace with your editor when you wish to return the closing tags.

    0 讨论(0)
  • 2020-12-28 14:07

    Yes, to comment structural metadata out,

    Using <script>/* ... */</script> in .html

    Comment out large sections of HTML (Comment Out Block)

    my personal way in a .html file is opening: <script>/* and close it with */</script>

    <script>/* hiding code go here */</script>

    Is a workaround to the problem since is not HTML.

    Considering your code in .html...

      <!-- Here starts the sidebar -->
      <div id="sidebar">
      ....
      </div>
    
    <script>/*
      <!-- Here starts the main contents pane -->
      <div id="main-contents">
      ...
      </div>
    
      <!-- Here starts the footer -->
      <div id="footer">
      ...
      </div>
    */</script>
    

    And in a case is HTML inside PHP file using comment tag <?/* or <?php /* and close it with */?> . Remember that the file must be .php extension and don't work in .html.

    <?/* hiding code go here */?>

    Considering your code in .php...

      <!-- Here starts the sidebar -->
      <div id="sidebar">
      ....
      </div>
    
    <?/*
      <!-- Here starts the main contents pane -->
      <div id="main-contents">
      ...
      </div>
    
      <!-- Here starts the footer -->
      <div id="footer">
      ...
      </div>
    */?>
    

    Is worth nothing that is not HTML but a common developer practice is to comment out parts of metadata so that it will not be rendered and/or executed in the browser. In HTML, commenting out multiple lines can be time-consuming. It is useful to exclude pieces of template structural metadata containing comments, CSS or code and systematically commenting out to find the source of an error. It is considered a bad practice to comment blocks out and it is recommended to use a version control system. The attribute "type" is required in HTML4 and optional in HTML5.

    0 讨论(0)
  • 2020-12-28 14:14

    Put a space between the "-->" of your header comments. e.g. "- ->"

    0 讨论(0)
提交回复
热议问题