所选单选上的按键事件 [英] Keypress event on chosen single select

查看:64
本文介绍了所选单选上的按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在选择的jquery单选上按下回车键时自动添加选择的值.那么,是否存在像按键之类的事件,当按下回车键时,我会用它来做某事?

I would like to automatically add the selected value when enter key is pressed on chosen jquery single select. So, for that is there any event like keypress which I would use to do something when return key was pressed?

<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>

推荐答案

在初始化后将keyup事件绑定到选定的jquery下拉列表上.

Bind the keyup event on the jquery chosen dropdown, after chosen in initialized.

根据版本,您需要使用.chosen-container.chzn-container.

Depending upon the version either you need to use .chosen-container or .chzn-container.

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

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

这篇关于所选单选上的按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆