multiple selections with datalist

百般思念 提交于 2019-11-28 06:51:47

Multiple currently working only with input type="email" and only in Chrome and Opera

look at this minimalist example:

<input type="email" list="emails" multiple>
<datalist id="emails">
    <option value="first@example.com">
    <option value="second@example.com">
    <option value="third@example.com">
    <option value="last@example.com">
</datalist>

<input type="text" list="texts" multiple>
<datalist id="texts">
    <option value="black">
    <option value="gold">
    <option value="grey">
    <option value="pink">
    <option value="turquoise">
    <option value="red">
    <option value="white">
</datalist>

( http://jsfiddle.net/iiic/t66boyea/1/ )

First input will be working, second NOT. You only press comma, and list will appear as same as on click into input.

Customized datalist to accept multiple values:

https://jsfiddle.net/bhbwg0rg/1/

After each entry press ,(Comma) and then Spacebar

<label for="authors">Type authors from favorite to least favorite</label>
<input type="text" list="names-list" id="authors" value="" size="50" name="authors" placeholder="Type author names">
<small>You can type how many you want.</small>
<datalist id="names-list">
  <option value="Albert Camus">
  <option value="Alexandre Dumas">
  <option value="C. S. Lewis">
  <option value="Charles Dickens">
  <option value="Dante Alighieri">
</datalist>

According to this 'multiple' attribute is only valid with email and file input types.

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