简体   繁体   English

HTML 下拉列表是否有 LB_SETITEMDATA 等效项?

[英]Is there a LB_SETITEMDATA equivalent for an HTML drop-down list?

In the Windows SDK there was a method to add extra (hidden) data to each listbox item, LB_SETITEMDATA.在 Windows SDK 中有一种向每个列表框项 LB_SETITEMDATA 添加额外(隐藏)数据的方法。 It was very useful, ie you could associate an index number with the item.这非常有用,即您可以将索引号与项目相关联。

Using HTML's drop-down list and JavaScript, I was hoping there might be a similar feature.使用 HTML 的下拉列表和 JavaScript,我希望可能有类似的功能。

In HTML5, there is a feature called data attributes, that allows you to add extra data to an HTML component.在 HTML5 中,有一个称为data属性的特性,它允许您向 HTML 组件添加额外的数据。

They are not completely hidden though since the user could inspect your page and see those values there.但是它们并没有完全隐藏,因为用户可以检查您的页面并在那里看到这些值。 So I wouldn't recommend using any sensitive information there.所以我不建议在那里使用任何敏感信息。

That said, they are visually hidden in the webpage, so is still very useful.也就是说,它们在视觉上隐藏在网页中,因此仍然非常有用。 Here is an example (note you can see the data on the code, but not on the rendered result):这是一个示例(请注意,您可以在代码中看到数据,但无法在渲染结果中看到数据):

 <p>Fruits:</p> <select> <option data-color="red">Apple</option> <option data-color="yellow">Banana</option> </select>

Reference: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes参考: https : //developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM