评论中的 HTML 评论?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3773719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML comments within comments?
提问by Tony R
Is there a way to comment multiple lines... which already have some comments in them?
有没有办法评论多行......其中已经有一些评论?
i.e.
IE
<html>
<!-- Multi-line comment begin
<head>
<!-- This script does abcxyz -->
<script>...</script>
</head>
<body>
Hello world!
</body>
Multi-line comment end -->
</html>
It seems that even SO's syntax hilighting won't accept this...
似乎即使是 SO 的语法高亮显示也不会接受这个......
采纳答案by álvaro González
I think the key point is this:
我认为关键是这样的:
Note that comments are markup.
请注意,注释是标记。
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4
This is not valid markup:
这不是有效的标记:
<div <span/> />
... so neither is the one you mention.
......所以你提到的那个也不是。
Since all my sites are written in PHP I normally comment out code with PHP comments:
因为我所有的网站都是用 PHP 编写的,所以我通常用 PHP 注释来注释代码:
<?/*?>
<div>...</div>
<p>...</p>
<?*/?>
Perhaps you can use a similar trick.
也许您可以使用类似的技巧。
回答by Quentin
No. Comments cannot be nested and HTML has only one style of comment.
不可以。注释不能嵌套,HTML 只有一种注释样式。
回答by Florian
No. The closing comment tag --> will always end the comment section so if your comment includes a comment the closing tag of your included comment will end the comment section.
不。结束评论标签 --> 将始终结束评论部分,因此如果您的评论包含评论,您所包含评论的结束标签将结束评论部分。
You can do a replace of --> in the section you are about to comment out to something unique so you can later just do another replace back to --> if you choose to undo your commenting.
您可以在将要注释掉某些独特内容的部分中替换 -->,以便稍后再替换回 --> 如果您选择撤消注释。
回答by Mathijs Flietstra
If you're really stuck with some piece of HTML – pre-rendered at some uncontrollable source – which contains comments, and you need to make sure none of it is rendered on your page, you can always wrap it with a script
tag like below, only thing is, you can't comment out script
tags this way.
如果你真的被某些 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>
If you need to comment out script
tags, you could use a textarea
as wrapper instead, off course doing it this way, you can't comment out textarea
tags.
如果你需要注释掉script
标签,你可以使用 atextarea
作为包装器,当然这样做,你不能注释掉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>
回答by Matti Virkkunen
Nope, unfortunately HTML comments don't nest.
不,不幸的是 HTML 注释不嵌套。
回答by monireh d
it may still be useful for some developers, if use use vsCode as your IDE you can use an extension named Nest Comments in visual studio code market which work like a charm.
它可能对某些开发人员仍然有用,如果使用 vsCode 作为您的 IDE,您可以在 Visual Studio 代码市场中使用名为 Nest Comments 的扩展,它就像一个魅力。
this is the linkNest Comments
这是链接巢评论