[英]How can I make an arrow on an instruction box on the right move to point to the field on the left that is in focus?
[英]when a text box is on focus, how can I make a listen to a down arrow press
我想要这个来完成自动搜索。 它正在工作。 我现在想要的全部内容是,在键入时按下向下箭头键,焦点将移至下拉列表。
您可以订阅onkeydown
事件:
<input type="text" onkeydown="myFunc(this, event)" />
然后在函数内部检查键代码,以使用该代码确定按下了哪个键:
function myFunc(sender, e) {
var key = e.which ? e.which : e.keyCode;
if (key === 38) {
// up arrow was pressed
}
}
这是一个演示 。
就将焦点设置为给定元素而言,您可以使用focus()
函数:
document.getElementById('id_of_element').focus();
我倾向于使用一个库来存放这种东西。 John Resig的jQuery Hotkeys大部分时间都在工作。 您可以使用focus和blur事件来绑定和取消绑定热键处理程序:
handlerFn = function() { ... };
$('input.my-text-box').focus($(document).bind('keyup', 'down', handlerFn);
$('input.my-text-box').blur($(document).unbind('keyup', handlerFn));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.