通常当我有一个 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/