简体   繁体   中英

How to make a dropdown box(select element) to accept text search in html?

I have a drop down(select element) box. What I want is to be able to search the options in the same element by typing. I have tried the datalist in html5, but in that the typed value will be accepted as input if there is no value in options. I want the option to be chosen from the option list, but should be able to find it by typing a text.

 <select name="xyz">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>

here if I type "A" to search the option a should be chosen. If I type "X" to search it should not be accepted as an input.

You can use <datalist>

<input type=text list=browsers>
<datalist id=browsers>
  <option value="Firefox">
  <option value="InternetExplorer">
  <option value="Chrome">
  <option value="Opera">
  <option value="Safari">
</datalist>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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