I am working on key mapping. The problem is that when I press the TAB button down it navigates to the next input field.
TAB has key of 9 and
DOWN has key of 40
But, what is the JavaScript key code to go to the previous input field (SHIFT + TAB)?
What I want is to go to next link; what is keycode or code for the previous link?
Please help. Thanks.
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
}
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();
}
}
您可以event.shiftKey
使用event.shiftKey
属性: http : //www.java2s.com/Code/JavaScript/Event/Shiftkeypressed.htm
in my GWT case
if(event.isShiftKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_TAB){
//Do Something
}
This way it worked for me(By checking first if one of key is pressed and then check other inside it):
if (e.code === "Tab") {
if (e.shiftKey) {//shift+tab pressed
//Code
} else {//only tab pressed
//Code
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.