Javascript shift+tab 的键码是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3044083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:04:22  来源:igfitidea点击:

what is the key code for shift+tab?

javascripthtml

提问by rajesh

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 按钮时,它会导航到下一个输入字段。

TAB has key of 9 and
DOWN has key of 40

TAB 键为 9,
DOWN 键为 40

But, what is the JavaScript key code to go to the previous input field (SHIFT + TAB)?

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

What I want is to go to next link; what is keycode or code for the previous link?

我想要的是去下一个链接;上一个链接的键码或代码是什么?

Please help. Thanks.

请帮忙。谢谢。

回答by Nick Craver

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
}

回答by bit-less

e.keyCodehas been deprecatedfor sometime. Use "e.key" KeyboardEvent.keyinstead.

e.keyCode已被弃用一段时间。改用“e.key” KeyboardEvent.key

Usage:

用法:

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

Example:

例子:

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

回答by knittl

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

您可以使用该event.shiftKey属性:http: //www.java2s.com/Code/JavaScript/Event/Shiftkeypressed.htm

回答by touchchandra

in my GWT case

在我的 GWT 案例中

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