Determine if an element was selected from HTML 5 datalist by pressing enter key

时光怂恿深爱的人放手 提交于 2019-12-02 04:40:26

Unfortunately, this is currently not possible at all. The input event is only fired once the value inside the input actually changes, which always comes after making your selection. The event does not hold information on how this was added.

An alternative would be to track the actual click or keypress events. However, neither the click event nor any of the keypress events seem to be fired when using the datalist (at least not in Chrome). Even if you bind them on the document or body, clicks or keypresses simply do not register when performed on the actual datalist.

As such, it is impossible to tell the difference between these methods of selecting a datalist option.

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