且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ExtJs选项卡上实现accesskey?

更新时间:2022-02-19 22:01:05

这个的核心是创建一个键盘映射,键,一旦检测到,您可以添加一个自定义处理程序。

The core to this is creating a keymap to recognise you are pressing a combination of keys, once this is detected you can then add a custom handler.

参见这里: http://dev.sencha.com/deploy/dev/docs/?class=Ext.KeyMap

例如:

var map = new Ext.KeyMap("my-element", [
    {
        key: [10,13],
        fn: function(){ alert("Return was pressed"); }
    }, {
        key: "abc",
        fn: function(){ alert('a, b or c was pressed'); }
    }, {
        key: "\t",
        ctrl:true,
        shift:true,
        fn: function(){ alert('Control + shift + tab was pressed.'); }
    }
]);

以上是一些示例映射,您只需将my-element替换为您希望的元素寻找按键(所选择的元素会检测到它们)。如果您希望具有APPLICATION宽键映射,则该元素应该是页面的主体,窗口本身或ExtJS视口(如果使用的话)/主元素。这意味着您可以在应用程序的任何区域内,并且检测到按键。您在fn属性下定义的后续行为(即更改选项卡等)...

Above are a number of sample mappings, you simply replace 'my-element' with the element you wish to look for the key presses on (so which element when selected will detect them). If you wish to have APPLICATION wide key mapping, this element should either be the body of the page, the window itself or the ExtJS Viewport (if you are using one) / Master element. This will mean you can be within any area of your application and the keypress is detected. The subsequent behaviour you define under the 'fn' property (i.e. change tab etc)...