Firebug: “The 'charCode' property of a keyup event should not be used. The value is meaningless.”

前端 未结 3 1318
故里飘歌
故里飘歌 2021-01-21 10:06

I\'m building a calculator, and am using the following:

jQuery(function($) {
    $(\'#Quantity\').keyup(function() {
        console.log($(this).val());
    });
         


        
3条回答
  •  情深已故
    2021-01-21 10:42

    It appears because jQuery uses its own event object instead of a native browser one, and in the process of creating this object reads every possible property of an event, including charCode:

    props = [ ... "charCode" ... ]
    
    for ( var i = this.props.length, prop; i; ) {
        prop = this.props[ --i ];
        event[ prop ] = originalEvent[ prop ];
    }
    

    Firefox rightly warns you that you don't want to read charCode in the case of keyup events, not realising that you're just copying it, not actually doing anything with it. Consequently any page you create with jQuery keyup/keydown handlers will spit endless warnings.

    (IMO, jQuery should not bother copy this property. In the only case you actually want to use it—keypress—you can just use plain old which.)

提交回复
热议问题