80后的男生都知道的一句口诀:上上下下左右左右BA

1;实现在web上监听敲击键盘的动作
keydown,对,就使用这个来监听敲击键盘的事件
比如:
$(this).keydown(function (event) { alert(event.keyCode); });
2;获取上上下下左右左右BA对应的键盘code
经过上面的jquery代码。我们很容易得到这些键盘时间对应的code
"38,38,40,40,37,39,37,39,66,65";
3;最终代码
$(document).ready(function(){ var code = "38,38,40,40,37,39,37,39,66,65"; var kkeys = []; $(this).keydown(function (event) { kkeys.push( event.keyCode ); if(kkeys.toString().indexOf( code ) >= 0){ alert("上上下下左右左右BA,口诀激活。"); kkeys = []; } }); });