Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
今天我决定通过用户脚本将 html5 数据列表添加到某些输入中。这是代码。问题是list没有添加属性。如果我将其更改为不同于 的任何内容list,例如lst- 它就在那里。
list
lst
应该是这样吗?这种行为是由规范还是由浏览器设置的?
好的,我对此进行了一些研究。
Spec说返回input.list相关的datalist对象,而不是属性值。所以你应该setAttribute('list','edit-subject-themes')在输入上使用,效果很好。好像是 jQuery 问题。
input.list
setAttribute('list','edit-subject-themes')
问题解决后,我肯定会在用户 JavaScript 中大量使用该技术 :)