我想要这个用于自动完成搜索。它在工作; all I want now 当键入时按下向下箭头键时,焦点将移动到下拉列表。
我倾向于使用图书馆来处理这类东西; 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));