Getting “The 'charCode' property of a keydown event should not be used. The value is meaningless” error in jQuery

孤者浪人 提交于 2019-12-01 17:27:24

问题


I'm getting "The 'charCode' property of a keydown event should not be used. The value is meaningless" error in firefox using jQuery. My code looks like this:

$("div#center-box div#empid-textbox input.id").keydown(function(e){
   key = e.which;
   if(key===13){
      //do something;
   };
});

does anyone know how to remedy this error?


回答1:


FIXED!!!

Seems like FF is not liking the 'keydown' function...I changed it to 'keypress' and it works perfectly.




回答2:


Check the first comment on http://api.jquery.com/event.which/

I found the same annoying behaviour using jQuery 1.4.2 with Firefox 3.6.3 as well. The fix for me was to remove "charCode" from the list of cloned attributes in line 1956 of jquery-1.4.2.js -- this list contains attributes to be cloned from the original event in the browser to a tailored jQuery event object that is more sane. Reading the "charcode" attribute in the cloning procedure seemed to trigger the warning in the error console. Cloning of the actual attribute, be it "keyCode" or "charCode" seems to be handled fine if lines 1996-1998 are changed to:

if (!event.which && ((originalEvent.charCode || originalEvent.charCode === 0) ? event.charCode : event.keyCode)) {
  event.which = originalEvent.charCode || event.keyCode;
}

i.e. a more delicate cloning of the charCode property if present.



来源:https://stackoverflow.com/questions/2639055/getting-the-charcode-property-of-a-keydown-event-should-not-be-used-the-valu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!