隔江千里
如果您只想在连续按下多个键时触发处理程序,请尝试以下操作:jQuery.multipress = function (keys, handler) { 'use strict'; if (keys.length === 0) { return; } var down = {}; jQuery(document).keydown(function (event) { down[event.keyCode] = true; }).keyup(function (event) { // Copy keys array, build array of pressed keys var remaining = keys.slice(0), pressed = Object.keys(down).map(function (num) { return parseInt(num, 10); }), indexOfKey; // Remove pressedKeys from remainingKeys jQuery.each(pressed, function (i, key) { if (down[key] === true) { down[key] = false; indexOfKey = remaining.indexOf(key); if (indexOfKey > -1) { remaining.splice(indexOfKey, 1); } } }); // If we hit all the keys, fire off handler if (remaining.length === 0) { handler(event); } });};例如,要在圣火上jQuery.multipress([83, 84], function () { alert('You pressed s-t'); })