[英]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.