为什么 HTML 验证器会给我关于此 HTML 注释的错误? [英] Why does the HTML validator give me an error about this HTML comment?
问题描述
这只是关于 HTML 页面内的注释的问题.
This is just question about comments inside of an HTML page.
例如:
<html>
<head></head>
<body>
<!--
<p><font size="4">--</font></p>
-->
</body>
</html>
使用 http://validator.w3.org/check 我收到以下错误消息.有意义吗?
Using http://validator.w3.org/check I get the following error message. Does it make sense?
第 6 行,第 21 列:无效的注释声明:找到字符<"外部注释但内部注释声明
Line 6, Column 21: invalid comment declaration: found character "<" outside comment but inside comment declaration
<p><font size="4">--</font></p>
检查您的评论是否使用了正确的语法,例如:.如果您忘记最后一个--"来关闭一个评论,然后又打开另一个评论,则可能会出现此错误.
Check that you are using a proper syntax for your comments, e.g: . This error may appear if you forget the last "--" to close one comment, and later open another.
推荐答案
是的,很有道理.
要了解错误信息,您必须了解注释标签.它由三个关键部分组成,开始标记的 <!
,开始和结束注释的 --
,以及 >
> 结束标签.
To understand the error message, you have to understand the comment tag. It consists of three key parts, the <!
that starts the tag, the --
that starts and ends the comment, and the >
that ends the tag.
当您将 --
放在评论文本中时,您实际上结束了评论部分.标签结束前的其余文本无效,因为它不是评论,您只能在评论标签内添加评论.
When you put --
inside the text of a comment, you actually end the comment part. The rest of the text until the end of the tag is invalid, as it's not a comment, and you can only have comments inside the comment tag.
您还可以在标签中包含多个评论:
You can also have more than one comment in the tag:
<!-- comment -- -- another comment -->
这篇关于为什么 HTML 验证器会给我关于此 HTML 注释的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!