html - 如何使用 <noscript> 元素 "right"?

标签 html validation

我今天找到的 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/

相关文章:

javascript - 拒绝应用 {filename} 的样式,因为它的 MIME 类型 ('text/html' ) 不是受支持的样式表 MIME 类型

javascript - Materialize CSS Sidenav 根据表单导航选择加载内容

javascript - 使用 d3 通过 id 将表格附加到 svg

java - libgdx AssetManager 无法仅在 html5 上加载资源

java - Struts 2.5 更新操作 validator 问题(条件验证)

c# - ASP.NET Core 5.0 MVC 中的自定义字段验证错误

html - 多个图像下方的文本对齐

php - 回车在 javascript-php 上下文中的意义是什么?

wpf - 是否可以在 WPF 中使用 ReactiveUI 绑定(bind)仅通过 INotifyDataErrorInfo 验证用户输入?

java - 检查字符串是否包含 HTML?如果包含则将其视为普通文本