HTML5自定义数据属性的命名规则(data-) [英] Naming rules for HTML5 custom data attribute(data-)
问题描述
我尝试使用data-userId
,但是Firebug将其显示为data-userid
(小写的"i").
似乎我们不应该在自定义数据属性中使用大写字母.
HTML5自定义数据属性的命名规则是什么?
请让我知道使用它的最佳方法.
I tried to use data-userId
, but firebug shows it as data-userid
(with a lowercase "i").
It seems that we should not use uppercase letters in custom data attributes.
What is the naming rules for HTML5 custom data attributes?
Please let me know any best practices to use it.
推荐答案
直接从规范:
3.2.3.9使用data-"开头,并且在连字符后至少有一个字符,为大写ASCII字母.
3.2.3.9 Embedding custom non-visible data with the
data-*
attributesA custom data attribute is an attribute in no namespace whose name starts with the string "
data-
", has at least one character after the hyphen, is XML-compatible, and contains no uppercase ASCII letters.
(添加了重点)
XML兼容是什么意思?
What does XML-compatible mean?
如果
Attribute names are said to be XML-compatible if they match the
Name
production defined in XML and they contain no U+003A COLON characters (:).
Name
生产规则是什么?
[4]
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]
[4a]NameChar
:: =NameStartChar
| "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
[5]Name
:: =NameStartChar
(
NameChar
)*
[4]
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]
[4a]NameChar
::=NameStartChar
| "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
[5]Name
::=NameStartChar
(
NameChar
)*
这篇关于HTML5自定义数据属性的命名规则(data-)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!