当我的输入类型为select(dropdown)时,我想按回车键来搜索数据,我可以按输入类型输入文本,但是当我使用drop down时不起作用。这是我的代码
原始HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<select class="form-control select2 select2-hidden-accessible" id="tot" name="tot" style="width: 100%;" tabindex="-1" aria-hidden="true">
<option value="Installation" data-icon="fa-check-square fa-fw text-blue">
<?php _e('Installation'); ?>
</option>
<option value="Maintenance" data-icon="fa-minus-square fa-fw text-yellow">
<?php _e('Maintenance'); ?>
</option>
<option value="Intervention" data-icon="fa-bug fa-fw text-red">
<?php _e('Intervention'); ?>
</option>
<option value="Replacement" data-icon="fa-external-link fa-fw text-teal">
<?php _e('Replacement'); ?>
</option>
<option value="Removal" data-icon="fa-circle fa-fw text-red">
<?php _e('Removal'); ?>
</option>
<option value="QualityControl" data-icon="fa-circle fa-fw text-red">
<?php _e('Quality Control'); ?>
</option>
</select>
用于演示
$('#tot').keyup(function(e) {
if (e.keyCode == 13) {
alert('jshd');
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<select class="form-control select2 select2-hidden-accessible" id="tot" name="tot" style="width: 100%;" tabindex="-1" aria-hidden="true">
<option value="Installation" data-icon="fa-check-square fa-fw text-blue">
Installation
</option>
<option value="Maintenance" data-icon="fa-minus-square fa-fw text-yellow">
Maintenance
</option>
<option value="Intervention" data-icon="fa-bug fa-fw text-red">
Intervention
</option>
<option value="Replacement" data-icon="fa-external-link fa-fw text-teal">
Replacement
</option>
<option value="Removal" data-icon="fa-circle fa-fw text-red">
Removal
</option>
<option value="QualityControl" data-icon="fa-circle fa-fw text-red">
Quality
</option>
</select>