How to capture enter key press for select2

后端 未结 2 1009
半阙折子戏
半阙折子戏 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 13:01

    Why not simply use this code to check as there can be a mouse click :

       
    
    $('#example').select2();
    
    $("#example").on("click change keydown", function (e) { 
            var keycode = (event.keyCode ? event.keyCode : event.which);       
            if (keycode == 13) {
                console.log('inside')
            }
        });
    
    

    Hope this helps.

提交回复
热议问题