html - div 需要 2 个 id 属性

标签 html

通常当我有一个 div 时,我使用 id 属性来唯一标识一个元素。

例如:

<div id="F123" class="sidebar-item">
    My first item goes here
</div>

现在,我的 div 元素需要一个双“键”:一个“slug”属性和一个“类别”属性。

例如:

<div slug="my-first-item" category="techno" class="sidebar-item">
    My first item goes here
</div>

编译器警告我这些属性无效。在 div 上设置双键的最佳方法是什么?我很确定有多种方法可以继续,但我想知道最好的方法是什么?

最佳答案

<div data-slug="my-first-item" data-category="techno" class="sidebar-item">
    My first item goes here
</div>

HTML data attributes .如果我可能会问,为什么认为你需要它?

关于html - div 需要 2 个 id 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9198446/

相关文章:

html - 如果父元素没有类 xy,则在元素上设置悬停类

java - 转义的 html 不会被转义(现在是 : unescaped html won't escape back)

c# - sql语法问题或者代码问题? "Index was outside the bounds of the array."

html - 如何修复此网站上的响应列?

javascript - Owl Carousel 安装问题

html - 对象之间的文本装饰空间

javascript - 如何将javascript附加到动态创建的元素?

html - Bootstrap Modal Input一弹出怎么传控件?

javascript - Kendo UI 下拉列表在 kendoWindow 内不起作用

HTML 连接文本输入和链接