HTML嵌套注释

时间:2013-08-09 11:41:56

标签: html comments

假设有些像这样的HTML ......

<section>
  <h1>Some stuff</h1>
  <!-- That was some stuff... -->
</section>

我在想要评论的HTML周围添加评论标签。我想评论一切,但评论已被现有评论关闭。

<!--
<section>
  <h1>Some stuff</h1>
  <!-- That was some stuff... -->
</section>
-->

在不丢失所有内联注释的情况下,处理此方案的最佳方法是什么。

5 个答案:

答案 0 :(得分:9)

HTML评论以<!--开头,以遇到的第一个-->结束。没有办法改变这种行为。如果您想隐藏一个大部分,其中可能包含开发期间的评论,则可以包含<div style="display:none"></div>。但是不要在生产中这样做,这很糟糕。

答案 1 :(得分:7)

使用嵌套注释注释块: sub inner(block)注释从“ - ”到“~~”

<!-- *********************************************************************
     * IMPORTANT: to uncomment section
     *            sub inner comments "~~" -> "--" & remove this comment
     *********************************************************************
<head>
   <title>my doc's title</title> <~~! my doc's title ~~>
   <link rel=stylesheet href="mydoc.css" type="text/css">
</head>

<body> 
<~~! my doc's important html stuff ~~>
...
...
...
</body>

*********************************************************************
* IMPORTANT: to uncomment section
*            sub inner comments "~~" -> "--" & remove this comment
*********************************************************************
--> 

因此,最外层评论忽略所有“无效”内部(块)评论

答案 2 :(得分:1)

据我所知,没有办法阻止它。 你需要注意你要评论的内容。

请参阅:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4

您可以尝试使用PHP注释掉HTML代码...... 希望它有所帮助!

答案 3 :(得分:0)

如果不删除内部注释,则无法对其进行注释,因为HTML会将代码视为

<!--
<section>
----
----            //All this code comes under commented
----
some stuff... -->

它只考虑<section>之前的开始评论标记和“某些东西......”之后的结束评论标记。因此,HTML不会在<h1>之后处理评论标记。

答案 4 :(得分:0)

这对我有用:

<!--[if False]>
Lots of html including <!-- comments -->
<![endif]-->