我的网站上有一个Select2下拉列表,如果用户点击下拉列表外的其他内容,我希望关闭下拉列表,如果他们点击了#34;已完成"在iOS的键盘上。这是我的尝试(目标都没有实现):
$(function() {
$('select').select2({
dropdownAutoWidth : true
});
// My attempt at closing the dropdown on press of "done"
$('select').bind("keypress", function(e){
if(e.which === 13){
$('select').select2('close');
}
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"/>
<select>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
<option>Option 6</option>
<option>Option 7</option>
<option>Option 8</option>
<option>Option 9</option>
<option>Option 10</option>
</select>
&#13;