DOM ID 中允许使用哪些字符? [英] What characters are allowed in DOM IDs?
问题描述
可能的重复:
HTML 中 id 属性的有效值是什么?
下划线看起来不错.破折号呢?其他特殊字符?
Underscores seem fine. What about dashes? Other special characters?
推荐答案
其实 HTML 和 XHTML 是有区别的.由于 XHTML 是 XML,因此适用于 XML ID 的规则:
Actually there is a difference between HTML and XHTML. As XHTML is XML the rules for XML IDs apply:
ID 类型的值必须与 Name 产生式匹配.
Values of type ID MUST match the Name production.
NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] |
[#xD8-#xF6] | [#xF8-#x2FF] |
[#x370-#x37D] | [#x37F-#x1FFF] |
[#x200C-#x200D] | [#x2070-#x218F] |
[#x2C00-#x2FEF] | [#x3001-#xD7FF] |
[#xF900-#xFDCF] | [#xFDF0-#xFFFD] |
[#x10000-#xEFFFF]
NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 |
[#x0300-#x036F] | [#x203F-#x2040]
对于 HTML,以下内容适用:
For HTML the following applies:
id = 名称 [CS]
此属性为元素分配名称.此名称在文档中必须是唯一的.
id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document.
ID 和 NAME 令牌必须以字母 ([A-Za-z]) 可以跟由任意数量的字母、数字([0-9])、连字符(-")、下划线(_")、冒号 (:") 和句点(.").
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
这篇关于DOM ID 中允许使用哪些字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!