Making HTML5 datalist visible when focus event fires on input

前端 未结 4 1136
花落未央
花落未央 2021-02-04 00:11

As some might know already styling select element is a nightmare, literally impossible without some javascript trickery. The new datalist in HTML5 could serve the same purpose s

4条回答
  •  失恋的感觉
    2021-02-04 00:50

    I hope you like this solution:

    I added a “temp” attribute to the input field for storage and once the mouse hovers over the input filed it will save its current value in temp and then delete the value so as to allow the datalist to open.

    On mouseout it will restore the field’s value from the variable temp. This solution works great under Chromium that I tested.

    As a bonus you can add a placeholder="Click to see all your options"

    
     
            

提交回复
热议问题