简体   繁体   English

如何使用箭头键从“选择”框中选择一个选项?

[英]How to select an option from Select box using arrow keys?

I have tried with .change() and/or with .select() , even with .click() , but no hope. 我尝试使用.change()和/或.select() ,甚至使用.select() .click() ,但都没有希望。

When I stop on a select box field with a Tab-focus, and when I press up or down I'd like that currently focused option item to be selected instantly. 当我停在以Tab键为焦点的选择框字段上时,当我按向上或向下时,我希望立即选择当前已聚焦的选项。

Is it possible to achive this with jQuery/JavaScript? 是否有可能通过jQuery / JavaScript实现呢?

This was more easy than I tought, with jQuery of course: 当然,这比使用jQuery更轻松,比我还容易:

$('#year').on('keyup', function() {
    $(this).change();
});

As Xander suggested, I just triggered the .on('keyup') event on top of the select box field, and on each change of the selected value of the select box it will automatically select it and I have the event working! 正如Xander所建议的,我只是在选择框字段顶部触发了.on('keyup')事件,并且在每次更改选择框的选定值时,它都会自动选择它,并且该事件正在起作用!

Thanks all others who helped. 感谢所有提供帮助的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Ajax建议文本框中使用箭头键选择数据 - Select data using arrow keys,from ajax suggestion text box 如何在选择选项上使用鼠标和箭头键? - how to work with mouse and arrow keys on select option? 如何使用for循环从选择选项框中获取值[选择选项框是动态创建的] - how to get values from select option box using for loop [select option box is created dynamically] JQuery 搜索框自动建议 - 如何使用箭头键从建议中进行选择,同时仍保持对输入字段的关注 - JQuery search box autosuggest - How to select from suggestions with arrow keys whilst still retaining focus on input field 如何使用Javascript通过选项的值在选择框中选择一个选项? - How to select an option in a select box by the value of the option using Javascript? 使用 jQuery/javaScript 从选择框中动态选择选项 - select dynamically option from select-box using jQuery/javaScript 在html中选择选项使用键javascript选择 - select option in html select using keys javascript 使用箭头键选择并突出显示元素 - Select and highlight element by using arrow keys 首先选择在Google Chrome中选择不可选择的箭头键 - Make first option of select unselectable through arrow keys in Google Chrome AngularJS:为什么我不能用箭头键从文本框中选择自动完成列表? - AngularJS: Why can't I select through my autocomplete list from a text box with my arrow keys?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM