Shift + tab 的关键代码是什么?

我正在研究密钥映射。问题是,当我按下 TAB 按钮时,它会导航到下一个输入字段。

TAB 的密钥是9和
向下键是40

但是,转到前一个输入字段(SHIFT + TAB)的 JavaScript 关键代码是什么呢?

我想要的是转到下一个链接; 什么是上一个链接的密钥或代码?

请帮帮我。 谢谢。

110125 次浏览

There's no "keycode", it's a separate property on the event object, like this:

if(event.shiftKey && event.keyCode == 9) {
//shift was down when tab was pressed
}

you can use the event.shiftKey property for that: http://www.java2s.com/Code/JavaScript/Event/Shiftkeypressed.htm

in my GWT case

if(event.isShiftKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_TAB){
//Do Something
}

e.keyCode has been deprecated for sometime. Use "e.key" KeyboardEvent.key instead.

Usage:

e.shiftKey && e.key === 'Tab'

Example:

function clicked(e) {
if (e.shiftKey && e.key === 'Tab') {
// Do whatever, like e.target.previousElementSibling.focus();
}
}

This way it worked for me
By checking first if one of key is pressed(tab/shift ) and then check other inside it:

if (e.code === "Tab") {
if (e.shiftKey) {//shift+tab pressed
//Code
} else {//only tab pressed
//Code
}
}