繁体   English   中英

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

[英]jquery keypress event object keyCode for firefox problem?

FireFox 的 jQuery String.fromCharCode(e.keyCode)事件在String.fromCharCode(e.keyCode)转换后为事件对象提供加密的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>

您应该在 Firefox 中使用e.charCode

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

在这里试试:

http://jsfiddle.net/REJ4t/

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

它适用于 IE 和 FF。

 $(document).ready(function (){

         $('#txtEntry').keypress(function (e) {

             $('#lnkValidEdit').focus();
             return false;

         });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM