jquery keypress事件对象keyCode for firefox问题?

Mr *_*der 11 javascript jquery events keycode keypress

FireFox的jQuery keypress事件keyCodeString.fromCharCode(e.keyCode)转换后为事件对象提供加密属性,但在Chrome中运行良好.

以下是javascript代码:

<!-- #booter and #text are ids of html element textarea -->

<script type="text/javascript">        
    $(function(){
        $('#booter').keypress(function(e){              
            var input = $(this).val() + String.fromCharCode(e.keyCode);
            $('#text').focus().val(input);
            return false;
        });
    });
</script>
Run Code Online (Sandbox Code Playgroud)

mam*_*moo 20

你应该e.charCode在Firefox中使用.

$("#booter").keypress(function(e){
     var code = e.charCode || e.keyCode;
     var input = $(this).val() + String.fromCharCode(code);
     $('#text').focus().val(input);
     return false;
});
Run Code Online (Sandbox Code Playgroud)

试试吧:

http://jsfiddle.net/REJ4t/

PS如果你想知道为什么会这么乱:http://www.quirksmode.org/js/keys.html