我正在开发一个基于 php 的网络应用程序,它非常庞大,所以我想在我的网站上设置一些键盘短切键,例如 [ { ctrl + H }, { Shift + P }.. ]。我已经参考了一些例子和技巧,但这些对我没有帮助,所以如果你对此有任何想法,请向我推荐。
我已经在keyDown
事件上尝试了 ASCII 键,但它不起作用。这是我的代码
<!doctype html>
<html>
<head>
<title>title</title>
<script>
var isCtrl = false;
document.onkeyup = function(e) {
if (e.which == 17)
isCtrl = false;
}document.onkeydown = function(e) {
if (e.which == 17)
isCtrl = true;
if (e.which == 77 && isCtrl == true) {
alert('this is demo');
return false;
}
}
</script>
</head>
<body>
<h3>Shorts Cuts</h3>
</body>
</html>
<button accesskey="h" onClick="alert('You clicked me!');">Press Alt+H!</button>
accesskey
是 Web 应用的强大属性。演示
http://www.openjs.com/scripts/events/keyboard_shortcuts/
上面的URL是一个不错的Javascript库的链接,用于做Javascript快捷方式,这是我能找到的最好的,当我做类似的事情时。这个库也适用于我测试过的所有最新浏览器。