键盘激活功能

Keyboard-activated function

在我客户的网站上,Javascript 中有一个功能,按 alt + 5 可激活此功能:

var chgpgPage = {
    goToPrincipal:function(){
        window.location.href = 'www.mysite.org';
    },
}      

触发函数的部分代码是这样的:

: this.AV102pressedSelected.Key == "alt+5"
? chgpgPage.goToPrincipal()

我现在需要 alt + 4 按钮来触发另一个功能:

require(["dojo", "dijit/form/Button"], function() {
    
    // Invert Button
    new dijit.form.Button({
        onClick: function() {
            dojo.toggleClass(document.documentElement, 'inverted');
        }
    }, 'invertButton');
    
});

触发代码看起来如何?

: this.AV102pressedSelected.Key == "alt+4"
? ???????????????????

您将如何触发上述功能?因为它不像另一个那样有 var?

今天 invertButton 函数由一个按钮触发:

<button id="invertButton">Click to Invert</button>

感谢您的帮助!

我想你可以像这样在chgpgPage中添加一个功能,

var chgpgPage = {
    goToPrincipal:function(){
        window.location.href = 'www.mysite.org';
    },
    invert:function(){
        require(["dojo", "dijit/form/Button"], function() {
            ojo.toggleClass(document.documentElement, 'inverted');
        });
    }
}

invert 函数将具有反转逻辑。您将触发此功能:

: this.AV102pressedSelected.Key == "alt+4"
? chgpgPage.invert()