-->

所选择单选择按键事件(Keypress event on chosen single select)

2019-10-19 05:01发布

我想自动添加所选值输入键被按下所选的jQuery次选择的时候。 因此,对于有类似的按键,我会用按下回车键的时候做一些事情无论如何?

<select id="myselect" data-placeholder="Add foods you can buy here." 
style="height:30px; width: 100%" class="chosen-select" onkeypress="handle(event)" >
<option value=""></option>
<optgroup label="blah">
<option>blah blah</option>
</optgroup>
</select>

Answer 1:

绑定keyup了jQuery选择的下落事件后,选择在初始化。

根据不同的版本,或者你需要使用.chosen-container.chzn-container

$(".chosen-select").chosen({});

$(".chosen-container").bind('keyup',function(e) {
    if(e.which === 13) {
        $('#myform').submit();
        // or your stuff here...
    }
});


Answer 2:

我通过使用suggesetd代码有problema Mahesh 。 如果是这样,使用按键来代替:

$(".chosen-container").bind('keypress',function(e) {
    if(e.which === 13) {
        $('#myform').submit();
        // or your stuff here...
    }
});


文章来源: Keypress event on chosen single select