【问题标题】:Keyboard-activated function键盘激活功能
【发布时间】:2020-10-26 20:24:32
【问题描述】:

在我客户的网站上,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>

感谢您的帮助!

【问题讨论】:

    标签: javascript button alt


    【解决方案1】:

    我觉得你可以像这样在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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-29
      • 2017-06-14
      • 2011-02-03
      • 2012-06-15
      • 2013-08-16
      • 2012-09-21
      • 1970-01-01
      • 2017-01-12
      相关资源
      最近更新 更多