我有一个可以通过键盘快捷键访问的按钮,但用户必须按ALT+ Z。无论如何让用户只需按下Z(或其他键)而无需按下即可访问按钮ALT?
非常感谢,
<input style="display:none;" id='stopButton1' type="button" value="Z" onclick="stop('z')" accesskey="z" />
我有一个可以通过键盘快捷键访问的按钮,但用户必须按ALT+ Z。无论如何让用户只需按下Z(或其他键)而无需按下即可访问按钮ALT?
非常感谢,
<input style="display:none;" id='stopButton1' type="button" value="Z" onclick="stop('z')" accesskey="z" />
不,这在纯 HTML 中是不可能的。
需要JavaScript:使用keypress事件检测特定的字符代码,并调用一些函数。
我们可以使用jquery 2.1.3插件keypress和ASCII价值
JS:
$(document).keypress(function (e) {
    if (e.which == 72 || e.which==104) {
        window.location.replace("http://soluvations.in");
    }
});
HTML:
<p>Press H/h to go to Home Page</p>
这是 JSFIDDLE 链接
我登陆这个页面寻找一种快速的方法来使 accesskey 在没有修饰符 (alt) 键的情况下运行。
如果其他人也在寻找相同的内容,我已将其添加到我的页面:
  $(document).on('keydown', function(e) {
    var link = $("a[accesskey=" + e.key + "]");
    if (link.length) {
      window.location = link.attr('href');
    }
  });
这将捕获按键,如果有与该accesskey集合的链接,它将重定向到其href.