我有一個無序列表,可以使用排序插件重新訂購。通過鍵盤導航無序列表 - JQuery
由於它不提供鍵盤支持,我已經開始爲此添加一個自定義函數,首先可以通過上/下箭頭鍵瀏覽列表。
Tabbing through the items works with tabindex added,then using the up/down arrows results jump over across multiple items items。
我已經設置了一些測試邊框顏色&可以看到prev &未選擇正確的下一項。
可以按Tab鍵進入以下頁面&嘗試使用箭頭鍵在列表...
$(document).ready(function(){
$("ul#sortable").sortable();
$("ul#sortable li").focus(function() {
$(this).css("border-color","red");
$previtem = $(this).prev('li');
$previtem.css("border-color","aqua");
$nextitem = $(this).next('li');
$nextitem.css("border-color","lime");
$(this).keydown(function(e){
if (e.keyCode == 40) { /* Focus Down */
$nextitem.focus();
return false;
} else if (e.keyCode == 38) { /* Focus Up */
$previtem.focus();
return false;
}
});
});
});
你的意思是這樣的嗎? http://jsfiddle.net/qYvNq/2/?應該給你一個想法。 – 2013-05-05 15:39:22