Firebug:“不应使用keyup事件的'charCode'属性.该值是没有意义的. [英] Firebug: "The 'charCode' property of a keyup event should not be used. The value is meaningless."

查看:95
本文介绍了Firebug:“不应使用keyup事件的'charCode'属性.该值是没有意义的.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个计算器,并且正在使用以下内容:

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

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

问题1:keyup()是否适合使用正确的事件?

Q1: Is keyup() the right event to be using?

Q2:为什么Firebug告诉我不应使用keyup事件的'charCode'属性.该值没有意义"?我注意到它的作用与我在Stackoverflow中键入此问题相同,所以我一定不能做错得太厉害的事.

Q2: Why is Firebug telling me "The 'charCode' property of a keyup event should not be used. The value is meaningless"? I noticed that it's doing the same thing as I type this question into Stackoverflow, so I must not be doing something too awfully wrong.

推荐答案

它的出现是因为jQuery使用其自己的event对象而不是本机浏览器对象,并且在创建该对象的过程中读取了事件的每个可能的属性. ,包括charCode:

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会正确地警告您,如果发生keyup事件,您不想阅读charCode,而不是意识到自己只是在复制它,而实际上并未对其进行任何操作.因此,您使用jQuery keyup/keydown处理程序创建的任何页面都会吐出无尽的警告.

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不应麻烦地复制此属性.只有在您实际要使用它的情况下-keypress,您才可以使用普通的which.)

(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.)

这篇关于Firebug:“不应使用keyup事件的'charCode'属性.该值是没有意义的.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆