2
我想用向上/向下箭頭鍵選擇在搜索結果中的項目,焦點的下一個鏈接與jQuery
下一個環節都不會然而專注,我究竟做錯了什麼?
住在http://jsfiddle.net/JJDfL/1/
$('#hitbox').on('keyup','a', function(event) {
//focus prev/next with arrows, enter and escape
if (event.keyCode == 27) {
$('#hitbox').slideUp(100);
$('#searchbox').val('');
$('#searchbox').focus();
}
if(event.keyCode == 40) {
var focused = $(':focus');
focused.parent().next().focus();
alert(focused.parent().next().html()); //returns '<a href="asdf">bb</a>'
}
});
UPDATE:
作品現在:
focused.parent().next().find('a').focus();
解決的問題。
謝謝,但在Chrome和ff 40觸發器(警報顯示)。嘗試在小提琴的搜索框中輸入「asdf」,#hitbox將由fake-ajax填充。 – Teson 2013-03-15 10:44:04
你說得對,我已經編輯了附加信息的答案。 – cernunnos 2013-03-15 11:15:17