How to turn off autocomplete while keep using datalist element in html

后端 未结 6 1977
萌比男神i
萌比男神i 2020-12-29 03:24

I have a input field which shows a list using html5 element. The problem is that with the browser au

6条回答
  •  猫巷女王i
    2020-12-29 03:50

    Is it possible for you to use the input field without an id or name attribute? Without that, the browser doesn't really have any way to associate a history with that element.

    In my real quick testing on Firefox, this seemed to do the trick:

    With id:
    With name:
    No id, name, class:
    With class:

    In the code above, the inputs with an id or name would remember past values, but the input without anything and the input with just a class would not remember anything.

    Unfortunately, this does make using the input slightly more difficult if you need it to have a name or id. In that case, I'd try having an id'ed input which is also display: none'ed and then use some JavaScript to keep it in sync with an input that won't remember past values.

提交回复
热议问题