jquery keypress事件对象keyCode为firefox问题? [英] jquery keypress event object keyCode for firefox problem?
本文介绍了jquery keypress事件对象keyCode为firefox问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FireFox的jQuery keypress事件为 String.fromCharCode(e.keyCode)$之后的事件对象
提供加密的 keyCode
属性c $ c>转换,但在Chrome中完美无瑕。
jQuery keypress event for FireFox gives encrypted keyCode
property for event object
after String.fromCharCode(e.keyCode)
conversion but works perfect in Chrome.
以下是JavaScript代码:
Following is the javascript code:
<!-- #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>
推荐答案
您应该使用 e。在Firefox中的charCode
。
$("#booter").keypress(function(e){
var code = e.charCode || e.keyCode;
var input = $(this).val() + String.fromCharCode(code);
$('#text').focus().val(input);
return false;
});
在此尝试:
PS
如果你想知道为什么所有这些混乱: http://www.quirksmode.org/js/keys.html
这篇关于jquery keypress事件对象keyCode为firefox问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文