html - Content-Script-Type 和 Content-Style-Type 有什么意义

标签 html stylesheet specifications w3c script-tag

考虑这两行:

<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />

来自 W3 关于 Scripting 的文档, 在 The default scripting language 部分:

Authors should specify the default scripting language for all scripts in a document by including the following META declaration in the HEAD

但它在 Local declaration of a scripting language 中继续说:

The type attribute must be specified for each SCRIPT element instance in a document. The value of the type attribute for a SCRIPT element overrides the default scripting language for that element.

在我看来这里有一个过度规范。为什么 需要 meta 和 per-script 类型声明?如果我们无论如何都“必须”单独声明每个标签,那么强制默认值有什么意义?

要么让默认值成为默认值,要么只是声明每个标签都需要它自己的类型——或者这里的措辞只是让我感到困惑?引用 style sheets 使用相同的语言

最佳答案

<script><style>元素只是向 HTML 添加脚本和样式的一种方式。

对于脚本,我们有事件处理程序属性,为了样式化 HTML 4.01 定义了 <link>元素,Link: HTTP header 和“style”属性。在每一种情况下,指定语言都不是强制性的,因此回退将是 Content-Script-Type 和 Content-Style-Type 的值。

例如:脚本部分说:

Documents that do not specify default scripting language information and that contain elements that specify an intrinsic event script are incorrect. User agents may still attempt to interpret incorrectly specified scripts but are not required to. Authoring tools should generate default scripting language information to help authors avoid creating incorrect documents.

样式部分有一个等效的语句:

Documents that include elements that set the style attribute but which don't define a default style sheet language are incorrect. Authoring tools should generate default style sheet language information (typically a META declaration) so that user agents do not have to rely on a default of "text/css".

请注意,这些要求不是 DTD 可表达的,因此依赖 DTD 的验证器不会将违规标记为错误。

我不知道是否有浏览器真正关注这些设置。

关于html - Content-Script-Type 和 Content-Style-Type 有什么意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6268181/

相关文章:

html - 表格内的分区

java - 是否可以使用 -fx-graphic 从 JavaFX CSS 样式表上的 jar 中引用图标?

javascript - JS 验证高亮输入字段红色/绿色

javascript - 在 jQuery 中单击 fadeToggle

javascript - XML解析远程服务器

html - 如何让 React Web 应用程序全屏显示

javascript - 如何在注册该组件时为 vue.js 组件定义 css 样式?

passport.js - 为什么现代 Passport 的机器可读区域中的复合校验位没有考虑所有数据?

conditional-statements - 在某些条件下读取序列图

JavaScript。数组元素初始化顺序