html datalist element auto suggest behavior

*爱你&永不变心* 提交于 2020-01-03 07:09:25

问题


I noticed that different browsers have different behavior regarding to suggesting values for a text field when you hook it up to a datalist. Some browsers show the entries which exactly starts with what you've typed(IE, older chrome versions), while others show entries which contain what you've typed as a sub-string (firefox, newer chrome versions).

For example, type i into the text box, and observe the suggestions:

browser: 
<datalist id="browsers">
    <option value="Google Chrome">Google Chrome</option>
    <option value="Internet Explorer">Internet Explorer</option>
    <option value="Firefox">Firefox</option>
    <option value="Opera">Opera</option>
    <option value="Safari">Safari</option>
    <option value="Others">Others?</option>
</datalist>
 <input type="text" name="browser" list="browsers">

(or here's a fiddle, if you prefer http://jsfiddle.net/yaj8ut3m/ )

In IE, it will suggest only Internet Explorer, but firefox & recent chrome will suggest Internet Explorer, Firefox, and Safari.

Is there some way to specify which auto suggest filtering behavior to use?

note: javascript solutions aren't acceptable


回答1:


This is unspecified option.

And known issue:

If you type "V" the list will show only items that start with "V" in Chrome, Opera and IE, and any <option> containing "V" in Firefox.



回答2:


If the question is:

"Is there some way to specify which auto suggest filtering behavior to use?

note: javascript solutions aren't acceptable"

the answer will (sadly) be: No there isn't, this depend on browser's implementation and the datalist tag hasn't any attribute.

I have to say that is full of "plugins" and is relatively simply to write one but using js.



来源:https://stackoverflow.com/questions/27762693/html-datalist-element-auto-suggest-behavior

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