html-select - 我可以在选择(下拉)中将自定义属性添加到选项值吗

标签 html-select html

这可能吗?我从不同的来源填写我的下拉列表。我正在考虑分离不同的条目 odf 添加一个像这样的自定义属性:

<option value="12" customatrribute: "123" >NAME</option>

最佳答案

你正在使用的属性被认为是无效的,如果你想自己做,你需要有data-前缀,因为它符合 HTML5 规范。

来自规范:

A custom data attribute is an attribute in no namespace whose name starts with the string "data-", has at least one character after the hyphen, is XML-compatible, and contains no characters in the range U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).

所以你可以使用类似的东西

<option value="12" data-customatrribute="123" >NAME</option>

另请注意,您需要使用 = 而不是 :


正如您评论的那样,这是源代码的屏幕截图,它确实为我显示了 enter image description here

关于html-select - 我可以在选择(下拉)中将自定义属性添加到选项值吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18957094/

相关文章:

html - 为什么这个 CSS 在我悬停时不创建新的菜单项?

html - 如何在 IE 的 HTML 选择下拉列表中设置字体系列?

php - 如何从数据库中的 2 个不同表中获取 Laravel 中选定选项的值

mysql - 硬核常量值比查询数据库更好吗?

html - 如何在不删除 Bootstrap 的情况下减少填充或边距

javascript - 是否有针对 htmlstring 的 JS diff 库,就像纯文本上的 google-diff-match-patch 一样?

javascript - 在 JQuery bPopup 中打开新页面

html - 即 : Unicode characters in HTML select and option tags

jquery - 使用 jquery 检查下拉选项选择框的最后一个值

css - 应用于 HTML 选择多个非 3D 背景的 css 是什么?