Getting “The 'charCode' property of a keyd

2019-02-22 19:44发布

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?

2条回答
The star\"
2楼-- · 2019-02-22 20:03

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.

查看更多
别忘想泡老子
3楼-- · 2019-02-22 20:18

FIXED!!!

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

查看更多
登录 后发表回答