HTML 5类名和ID [英] HTML 5 classnames and IDs
问题描述
我知道在HTML4类和id不能以数字开头。
I know that in HTML4 classes and id cannot start with numbers.
我编码在HTML 5 / php和许多我的id和类只有数字他们指向我的数据库中的主键为jquery ajax调用。
I am coding in HTML 5/php and alot of my ids and classes have just numbers in them that point to a primary key in my database for jquery ajax calls.
我找不到HTML5类和id规范的文档。在HTML 5中是否有类和id名称,例如
I cannot find the documentation for HTML5 classes and id spec. Is it valid in HTML 5 to have class and id names such as,
class="122"
id="13213"
我通过w3c一致性检查器运行我的输出代码,一切都很好,
I have ran my output code through w3c conformance checker and all is good, but still I would like confirmation!?
感谢
推荐答案
并详细描述了我的发现: id
attribute has more class
y in HTML5 。从那篇文章:
I’ve researched this thoroughly and wrote about my findings: The id
attribute got more class
y in HTML5. From that article:
HTML5摆脱了对
id
属性。除了在文档中是唯一的之外,唯一的要求是该值必须包含至少一个字符(不能为空),并且不能包含任何空格字符。
HTML5 gets rid of the additional restrictions on the
id
attribute. The only requirements left — apart from being unique in the document — are that the value must contain at least one character (can’t be empty), and that it can’t contain any space characters.
要使用Selectors API定位以CSS或JavaScript中的数字开头的类名或ID,您应该转义。例如,要定位 id =404
的元素,您不能只使用#404
- 您'd have to escape it as follows :
To target a classname or ID that starts with a digit in CSS or in JavaScript using the Selectors API, you should escape them. For example, to target the element with id="404"
, you can’t just use #404
— you’d have to escape it as follows:
#\34 04 {
background: pink;
}
这篇关于HTML 5类名和ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!