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

前端 未结 1 1859
臣服心动
臣服心动 2021-01-27 03:42
jQuery(document.body).on(\'input\', \'.icdCodeInput\', function (event) {

});

I have a HTML 5 datalist with class icdCodeInput. When I select an item

相关标签:
1条回答
  • 2021-01-27 04:04

    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.

    0 讨论(0)
提交回复
热议问题