一个HTML元素可以有多个ID? [英] Can an html element have multiple ids?

查看:134
本文介绍了一个HTML元素可以有多个ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的问题是,对于一个给定的元素,我可以为它分配多个ID吗?我知道一个ID在HTML / XHTML页面中必须是唯一的。

 < div id =nested_element_123 task_123>< / div> 

我知道我简单地使用一个类就有一个简单的解决方案。我只是很好奇以这种方式使用ID。

解决方案

没有。从 XHTML 1.0规范


在XML中,片段标识符是
类型ID,并且每个
元素只能有一个
类型为ID的单一属性。因此,在XHTML 1.0中,
id属性被定义为类型
ID。为了确保XHTML 1.0
文档是结构良好的XML
文档,在元素
上定义
片段标识符时,XHTML 1.0文档必须使用id属性以上所列。参阅
的HTML
兼容性指南,了解如何确保这些定位点
在为
XHTML文档提供媒体类型
text / html时向后兼容。



I understand that an id must be unique within an HTML/XHTML page.

My question is, for a given element, can I assign multiple ids to it?

<div id="nested_element_123 task_123"></div>

I realize I have an easy solution with simply using a class. I'm just curious about using ids in this manner.

解决方案

No. From the XHTML 1.0 Spec

In XML, fragment identifiers are of type ID, and there can only be a single attribute of type ID per element. Therefore, in XHTML 1.0 the id attribute is defined to be of type ID. In order to ensure that XHTML 1.0 documents are well-structured XML documents, XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above. See the HTML Compatibility Guidelines for information on ensuring such anchors are backward compatible when serving XHTML documents as media type text/html.

这篇关于一个HTML元素可以有多个ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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