Editable 'Select' element

前端 未结 4 1225
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 01:45

I would like to have a select element in the form but besides the options in the dropdown, it would be useful to be able to edit it and add new option but not with another i

4条回答
  •  庸人自扰
    2020-11-29 01:55

    Nothing is impossible. Here's a solution that simply sets the value of a text input whenever the value of the

jsfiddle: https://jsfiddle.net/nwH8A/

The next example adds the user input to the empty option slot of the

jsfiddle: https://jsfiddle.net/pu7cndLv/1/


DataList

In HTML5 you can also do this with the list attribute and element:



  
(click once to focus and edit, click again to see option dropdown)
jsfiddle: https://jsfiddle.net/hrkxebtw/

But this acts more like an auto-complete list; once you start typing, only the options that contain the typed string are left as suggestions. Depending on what you want to use it for, this may or may not be practical.

0 讨论(0)
查看其它4个回答
提交回复
热议问题