Firebug JS warning to jQuery 1.4.2 “The 'charCode' property of a keyup event should not be used. The value is meaningless.” To ignore it?

前端 未结 3 710
梦谈多话
梦谈多话 2020-12-21 04:20

Firebug 1.5.4 JavaScript warning : The \'charCode\' property of akeyupevent should not be used. The value is meaningless. To ignore it? Is ther

3条回答
  •  感动是毒
    2020-12-21 04:50

    The jQuery code itself normalizes every event in jQuery.event.fix

    // props includes 'charCode' - this will access it
    for ( var i = this.props.length, prop; i; ) {
      prop = this.props[ --i ];
      event[ prop ] = originalEvent[ prop ];
    }
    
    // also, later in the same function
    
    // Add which for key events
    if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) {
      event.which = event.charCode || event.keyCode;
    }
    

    One of these lines of code is going to access charCode, which in turn creates your warning... You don't even need to do anything in your event handler (illustrated on jsfiddle)...

    The "solution" I usually end up using is just running without JS warnings (errors still show up)

    You can safely ignore this message (assuming you aren't using charCode, and are indeed using which)

提交回复
热议问题