HTML5 datalists - displaying list of options programmatically

不羁的心 提交于 2019-12-08 03:09:54

问题


I'm new to HTML5 datalists. I have setup an <input type="text"> tied to a <datalist> following:

  • HTML datalist Tag - W3Schools
  • HTML5 Datalist: What You Need To Know - The JotForm Blog

For instance:

<input list="browsers" name="browser">
<datalist id="browsers">
    <option value="Internet Explorer">
    <option value="Firefox">
    <option value="Chrome">
    <option value="Opera">
    <option value="Safari">
</datalist>

Chrome / Chromium shows the input as a combobox, allowing one to list all the possible values:

Firefox displays the input as any other text field, but I realized one can display all the options double clicking the field, or clicking the field and pressing the down arrow key:

I need to implement a browser-agnostic button that shows that list of options when it is clicked. Like:

<input list="browsers" name="browser">
<datalist id="browsers">
    <option value="Internet Explorer">
    <option value="Firefox">
    <option value="Chrome">
    <option value="Opera">
    <option value="Safari">
</datalist>
<button type="button">Show options</button>

How can I implement such a button?

来源:https://stackoverflow.com/questions/57696562/html5-datalists-displaying-list-of-options-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!