好吧,所以我正在尝试设置一个 keydown 调度程序,它将根据按下的键执行不同的操作。
它已添加到我的输入字段的 onkeyup
$(function() {
$("#myInput").keyup(suggestion_dispatcher);
});
然后这是建议调度程序本身
function suggestion_dispatcher() {
alert($(this).val());
var code = event.which;
if(code == 13) {
// select
} else if (code == 38) {
// up
} else if (code == 40) {
// down
} else {
$.proxy(get_suggestion(), $(this));
}
}
即使使用 jQuery 代理,在我的 get_suggestion() 函数中,如果我查看this
或者$(this)
我看到它给了我窗口对象而不是正在输入的输入框。我错过了什么?