$(document).on("keyup", function(e) {
var code = e.which;
var currentTabIndex = document.activeElement.tabIndex;
if (code == 40) {
alert(currentTabIndex);
//set tabIndex to currentIndex + 1;
} else if (code == 39) {
alert(currentTabIndex);
//set tabIndex to currentIndex + 1;
}
else if (code == 38) {
alert(currentTabIndex);
//set tabIndex to currentIndex - 1;
}
else if (code == 37) {
alert(currentTabIndex);
//set tabIndex to currentIndex - 1;
}
});
請參閱FIDDLE進行演示。如何在keydown或keyup上爲給定的activeElement tabIndex設置tabIndex?
你能描述你試圖達到的目標嗎? – Sampson 2014-12-03 01:14:18
@JonathanSampson如果按下鍵盤按鈕,tabindex焦點應該是當前具有選項卡Index焦點的元素之前的元素,否則如果按鈕keydown是按下,tabindex焦點應該是具有選項卡的當前元素之後的元素Index index :) – bumbumpaw 2014-12-03 01:18:12
因此,如果他們按下向上箭頭,請將第一個元素的「tabIndex」設置爲activeElement。如果他們按下向下箭頭,請使用大於activeElement的'tabIndex'來關注第一個元素? – Sampson 2014-12-03 01:20:28