web前端|js教程
js按键事件,and事件调度
web前端-js教程
1. Best的方法还是
仿源码论坛,手机控制ubuntu开机,证件照爬虫,tvtropes php,冀州seo外包lzw
objEvtMap[ id+evt ]=function(evt,element)
2. Event bind
firefox 网页源码,ubuntu18.4搜狗,虚拟机上重启tomcat,头条用户爬虫,php提取图片特征,百度竞价代理哪里专业seo推广lzw
function bindEvent_4_dataBlock(){var arr=$("#table1 li");arr.each(function(index, element) {$(element).keypress(function(){alert(keypress);});var+index;$(element).attr("id","data_aid_"+index);objEvtMap[ id ]=function(evt,element){if(evt=="down")key_press_hadler($(element));if(evt=="up")key_press_hadler4up($(element));if(evt=="left"){};if(evt=="rit"){}};});}
3. Event dispatch
jforum 源码,ubuntu用什么解压,爬虫利器之二,发票php,seo妍照片lzw
document.onkeydown=function(event){var e = event || window.event || arguments.callee.caller.arguments[0];alert("keycode:"+e.keyCode);if(e && e.keyCode==40 ){//下//alert(40=下键,39=右键);var now=$(".selected");var id=$(now).attr("id");var func=objEvtMap[id ];func("down",now);//key_press_hadler(now);return false;}
js中获取键盘事件
document.onkeydown=function(event){var e = event || window.event || arguments.callee.caller.arguments[];if(e && e.keyCode==){ // 按 Esc //要做的事情}if(e && e.keyCode==){ // 按 F //要做的事情} if(e && e.keyCode==){ // enter 键//要做的事情}};
只要你定义了这些键的动作,你在浏览器里按下这些键就会响应,兼容目前所有浏览器。
js 里面的键盘事件经常用到,所以收集了键盘事件对应的键码来分享下:
keyCode = BackSpace BackSpacekeyCode = Tab TabkeyCode = ClearkeyCode = EnterkeyCode = Shift_LkeyCode = Control_LkeyCode = Alt_LkeyCode = PausekeyCode = Caps_LockkeyCode = Escape EscapekeyCode = spacekeyCode = PriorkeyCode = NextkeyCode = EndkeyCode = HomekeyCode = LeftkeyCode = UpkeyCode = RightkeyCode = DownkeyCode = SelectkeyCode = PrintkeyCode = ExecutekeyCode = InsertkeyCode = DeletekeyCode = HelpkeyCode = equal bracerightkeyCode = exclam onesuperiorkeyCode = quotedbl twosuperiorkeyCode = section threesuperiorkeyCode = dollarkeyCode = percentkeyCode = ampersandkeyCode = slash braceleftkeyCode = parenleft bracketleftkeyCode = parenright bracketrightkeyCode = a AkeyCode = b BkeyCode = c CkeyCode = d DkeyCode = e E EuroSignkeyCode = f FkeyCode = g GkeyCode = h HkeyCode = i IkeyCode = j JkeyCode = k KkeyCode = l LkeyCode = m M mukeyCode = n NkeyCode = o OkeyCode = p PkeyCode = q Q atkeyCode = r RkeyCode = s SkeyCode = t TkeyCode = u UkeyCode = v VkeyCode = w WkeyCode = x XkeyCode = y YkeyCode = z ZkeyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_ KP_keyCode = KP_Multiply KP_MultiplykeyCode = KP_Add KP_AddkeyCode = KP_Separator KP_SeparatorkeyCode = KP_Subtract KP_SubtractkeyCode = KP_Decimal KP_DecimalkeyCode = KP_Divide KP_DividekeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = FkeyCode = Num_LockkeyCode = Scroll_LockkeyCode = acute gravekeyCode = comma semicolonkeyCode = minus underscorekeyCode = period colonkeyCode = numbersign apostrophekeyCode = plusminus hyphen macronkeyCode =keyCode = copyright registeredkeyCode = guillemotleft guillemotrightkeyCode = masculine ordfemininekeyCode = ae AEkeyCode = cent yenkeyCode = questiondown exclamdownkeyCode = onequarter onehalf threequarterskeyCode = less greater barkeyCode = plus asterisk asciitildekeyCode = multiply divisionkeyCode = acircumflex AcircumflexkeyCode = ecircumflex EcircumflexkeyCode = icircumflex IcircumflexkeyCode = ocircumflex OcircumflexkeyCode = ucircumflex UcircumflexkeyCode = ntilde NtildekeyCode = yacute YacutekeyCode = oslash OobliquekeyCode = aring AringkeyCode = ccedilla CcedillakeyCode = thorn THORNkeyCode = eth ETHkeyCode = diaeresis cedilla currencykeyCode = agrave Agrave atilde AtildekeyCode = egrave EgravekeyCode = igrave IgravekeyCode = ograve Ograve otilde OtildekeyCode = ugrave UgravekeyCode = adiaeresis AdiaeresiskeyCode = ediaeresis EdiaeresiskeyCode = idiaeresis IdiaeresiskeyCode = odiaeresis OdiaeresiskeyCode = udiaeresis UdiaeresiskeyCode = ssharp question backslashkeyCode = asciicircum degreekeyCode = sterlingkeyCode = Mode_switch
使用event对象的keyCode属性判断输入的键值
eg:if(event.keyCode==)alert(“enter!”);
键值对应表
AX U XBX V XCX W XDX X XEX Y XFX Z XGX XHX XIX XJX XKX XLX XMX XNX XOX XPX XQXESCXBRXCTRL XSXSHIFTXTXENTERXD
如果要使用组合键,则可以判断是否同时按下了这几个键,比如ctrl键、shift键以及alt键的组合使用就可以判断是否多按下了ctrl键、shift键以及alt键
如果觉得《Atitit.js的键盘按键事件捆绑and事件调度【javascript】》对你有帮助,请点赞、收藏,并留下你的观点哦!