San*_*ire 1 javascript jquery jquery-chosen
我想在选择的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>
Run Code Online (Sandbox Code Playgroud)
Mah*_*kal 10
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...
}
});
Run Code Online (Sandbox Code Playgroud)