How to capture enter key press for select2

后端 未结 2 1030
半阙折子戏
半阙折子戏 2021-01-22 12:10

I have a select2 dropdown for countries (multiselect). When user types keywords, it shows the related items in the menu.
For e.g., if user types ind, the menu shows

2条回答
  •  既然无缘
    2021-01-22 12:58

    The keypress event has been deprecated. You may want to use keydown instead.

    $(document).ready(function() {
      $('#example').select2();
    
      $(".select2-search__field").on("keydown", function(e) {
        if (e.keyCode == 13) {
          alert();
        }
      });
    });
    
    
    
    
    

提交回复
热议问题