html - 哪些 DOM 元素不能接受 id?

标签 html dom

我正在读这个 basic tutorial on canvas elements .以下句子中的 (almost) 引起了我的注意:

The id attribute isn't specific to the element but is one of the default HTML attributes which can be applied to (almost) every HTML element

哪些html元素不能接受id?

最佳答案

来自 w3schools (是的,我知道……):

Note: The id attribute is not valid in: <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.

请注意,这仅对 HTML4 有效,但这解释了本教程的“几乎”内容。

正如其他人所指出的,HTML5 接受所有元素的 id。

关于html - 哪些 DOM 元素不能接受 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11107463/

相关文章:

javascript - google 闭包库 sanitizer.sanitize 删除了我在 dom 元素上的 id

javascript - 使用 DOM - Javascript 生成 HTML 页面

javascript - 获取文件夹中最新添加的文件并将其显示在 html 页面上?

javascript - Uncaught ReferenceError : ReservationCard is not defined

html - tabindex - - 它是否得到广泛支持?

javascript - 如何防止在 Html 输入(组合框)中显示 val

html - 如何垂直对齐框大小 div 中的中间文本?

java - 使用 DOM 解析器更新 JAVA 中命名空间的输入 XML 文件

javascript - 什么时候在 DOM 环境中发生回流?

javascript - 在 onClick 中调用时,JavaScript 函数内未定义全局变量