我今天找到的 HTML 验证器 - http://html5.validator.nu/ - 说我使用了 <noscript>
元素不对。我的 XHTML 源代码是这样的:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<body>
<div id="head">
<noscript>
<p>JavaScript is disabled.</p>
</noscript>
...
验证器的错误信息是这样的:
Error: XHTML element noscript not allowed as child of XHTML element div in this context. (Suppressing further errors from this subtree.)
Contexts in which element noscript may be used:
- In a head element of an HTML document, if there are no ancestor noscript elements.
- Where phrasing content is expected in HTML documents, if there are no ancestor noscript elements.
Content model for element div:
- Flow content.
现在我继续阅读 Mozilla 文档并试图理解这意味着什么。我找到了一些关于内容类别、流内容、措辞内容、每个类别属于哪些元素(无论“属于”的确切含义)以及 <noscript>
的信息。可以使用元素。 ( https://developer.mozilla.org/en/HTML/Element/noscript )
我现在知道了:<div>
必须包含流量内容。 <noscript>
必须出现在措辞内容中。那显然不匹配。我该如何管理?不过,许多元素都属于流程和措辞类别。它们似乎不是分离集,所以有些人无法决定或者我不明白。
HTML 规范打算如何解决这个问题?
最佳答案
您不应使用 HTML5 验证器来验证您的 XHTML 1.1 文档。
HTML5 规范说明了 noscript
element :
The
noscript
element must not be used in XML documents.
所以 div
中的 noscript
在 XHTML5 中是不允许的,但在 XHTML 1.1 中是允许的。
关于html - 如何使用 <noscript> 元素 "right"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8066449/