评论中的 HTML 评论?
Posted
技术标签:
【中文标题】评论中的 HTML 评论?【英文标题】:HTML comments within comments? 【发布时间】:2011-04-15 23:32:55 【问题描述】:有没有办法评论多行...其中已经有一些 cmets?
即
<html>
<!-- Multi-line comment begin
<head>
<!-- This script does abcxyz -->
<script>...</script>
</head>
<body>
Hello world!
</body>
Multi-line comment end -->
</html>
似乎连 SO 的语法高亮都不接受这个……
【问题讨论】:
这有点烦人,但是您可以通过删除每个 cmets 的-->
部分来保留其他 cmets。
【参考方案1】:
我认为关键是这样的:
注意 cmets 是标记。
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4
这不是有效的标记:
<div <span/> />
...所以你提到的也不是。
因为我所有的网站都是用 php 编写的,所以我通常用 PHP cmets 注释掉代码:
<?/*?>
<div>...</div>
<p>...</p>
<?*/?>
也许你可以使用类似的技巧。
【讨论】:
嘘,真的吗?我是唯一一个因此而恶化的人吗? o.O 感谢您的 php 建议...【参考方案2】:没有。注释不能嵌套,HTML 只有一种注释样式。
【讨论】:
【参考方案3】:没有。结束评论标签 --> 将始终结束评论部分,因此如果您的评论包含评论,则包含的评论的结束标签将结束评论部分。
如果您选择撤消评论,您可以在即将注释掉的部分中替换 -->
【讨论】:
大声笑。我想这样做是可行的......:<--blahblah<--moreblahblah--<blahbleebloblah-->
(然后当你取消注释时,你会得到:blahblah<--moreblahblah--<blahbleebloblah
,这至少是一大堆,所以很明显 - 然后你只需将 )。【参考方案4】:
如果你真的被一些 HTML 卡住了——在一些不可控的源预渲染——它包含 cmets,并且你需要确保它没有在你的页面上呈现,你总是可以用 @ 包裹它987654321@标签如下,唯一的问题是,你不能这样注释掉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>
【讨论】:
【参考方案5】:不,不幸的是 HTML cmets 不嵌套。
【讨论】:
【参考方案6】:它可能对某些开发人员仍然有用,如果使用 vsCode 作为您的 IDE,您可以在 Visual Studio 代码市场中使用一个名为 Nest Comments 的扩展,它的工作原理就像一个魅力。
这是链接 Nest Comments
【讨论】:
这对我很有用。感谢分享!【参考方案7】:可以将其嵌入单引号或双引号中作为标签属性。这当然要求相应的引号不会出现在两者之间。
<html>
<br comm='Multi-line comment begin
<head>
<!-- This script does abcxyz -->
<script>...</script>
</head>
<body>
Hello world!
</body>
Multi-line comment end'>
</html>
http://jsfiddle.net/cehfumb2/2/
【讨论】:
以上是关于评论中的 HTML 评论?的主要内容,如果未能解决你的问题,请参考以下文章
iOS 中的 Facebook 评论与 loadHTMLstring
php 删除WordPress中的[All in One SEO Pack]或[Yoast SEO] HTML评论(适用于functions.php)