[英]HTML comments within comments?
有没有办法评论多行......其中已经有一些评论?
即
<html>
<!-- Multi-line comment begin
<head>
<!-- This script does abcxyz -->
<script>...</script>
</head>
<body>
Hello world!
</body>
Multi-line comment end -->
</html>
似乎即使是 SO 的语法高亮显示也不会接受这个......
我认为关键是这样的:
请注意,注释是标记。
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4
这不是有效的标记:
<div <span/> />
......所以你提到的那个也不是。
因为我所有的网站都是用 PHP 编写的,所以我通常用 PHP 注释来注释代码:
<?/*?>
<div>...</div>
<p>...</p>
<?*/?>
也许您可以使用类似的技巧。
不可以。注释不能嵌套,HTML 只有一种注释样式。
不。结束评论标签 --> 将始终结束评论部分,因此如果您的评论包含评论,您所包含评论的结束标签将结束评论部分。
您可以在将要注释掉某些独特内容的部分中替换 -->,以便稍后再替换回 --> 如果您选择撤消注释。
如果您真的坚持使用某些 HTML 片段(在某些无法控制的源中预先呈现),其中包含注释,并且您需要确保没有任何内容呈现在您的页面上,您始终可以使用如下所示的script
标记将其包装起来,唯一的问题是,您不能以这种方式注释掉script
标签。
<html> <head> </head> <body> <!-- multiline "comment" below using script type="text/html" --> <script type="text/html"> Hello world! <!-- Look at me, I'm a comment :) --> <div>Yeah, whatever, I'm an element..</div> </script> <span>Who cares, span is the man, the only visible one anyway!</span> </body> </html>
如果你需要注释掉script
标签,你可以使用textarea
作为包装器,当然这样做,你不能注释掉textarea
标签。
<html> <head> </head> <body> <!-- multiline "comment" below using textarea style="display:none;" --> <textarea style="display:none;"> <script> alert("which won't show up.."); </script> Hello world! <!-- Look at me, I'm a comment :) --> <div>Yeah, whatever, I'm an element..</div> </textarea> <span>Who cares, span is the man, the only visible one anyway!</span> </body> </html>
不,不幸的是 HTML 注释不嵌套。
可以将其作为标签属性嵌入单引号或双引号中。 这当然要求相应的引号不会出现在两者之间。
<html>
<br comm='Multi-line comment begin
<head>
<!-- This script does abcxyz -->
<script>...</script>
</head>
<body>
Hello world!
</body>
Multi-line comment end'>
</html>
它可能对某些开发人员仍然有用,如果使用 vsCode 作为您的 IDE,您可以在 Visual Studio 代码市场中使用名为 Nest Comments 的扩展,它就像一个魅力。
这是链接巢评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.