JS 代码
<html> <head> <script type = "text/javaScript"> window.onload = function () {hotkeyHandler.init (); } var hotkeyHandler = {currentMainKey : null, currentValueKey : null, init : function () {hotkeyHandler.register (0, "k", function () {alert ( "注册成功";}); }, 레지스터 : 함수 (태그, 값, func) {var mainkey = ""; 스위치 (태그) {case 0 : mainkey = 17; // ctrl break; 사례 1 : 메인 키 = 16; // 시프트 브레이크; 사례 2 : Mainkey = "18"; // alt break; } document.onkeyup = function (e) {hotkeyhandler.currentMainkey = null; } document.onkeydown = function (event) {// 获取键值 var keycode = event.keyCode; var keyValue = String.FromCharCode (event.keyCode); if (hotkeyHandler.currentMainKey! = null) {if (keyValue == value) {hotkeyHandler.currentMainKey = null; if (func! = null) func (); }} if (keycode == mainkey) hotkeyHandler.currentMainKey = 키 코드; }}} </script> </head> <body> 测试, 按下 ctrl+k 你就会发现神奇的事情发生了 </body> </html>