DOM ID中允许哪些字符? [英] What characters are allowed in DOM IDs?

查看:96
本文介绍了DOM ID中允许哪些字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

HTML中的id属性的有效值是什么?

下划线似乎很好。破折号怎么样?其他特殊字符?

Underscores seem fine. What about dashes? Other special characters?

推荐答案

实际上HTML和XHTML有区别。
由于XHTML是XML,适用于XML标识的规则:

Actually there is a difference between HTML and XHTML. As XHTML is XML the rules for XML IDs apply:


类型ID的值必须与名称生产相匹配。 >

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]


资料来源:可扩展标记语言(XML)1.0(第五版)2.3

对于HTML,适用以下条件:

For HTML the following applies:


id = name [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 (".").

资料来源: HTML 4规范,第6章,ID令牌

这篇关于DOM ID中允许哪些字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆