jquery keypress 事件对象 keyCode for firefox 问题? [英] jquery keypress event object keyCode for firefox problem?
本文介绍了jquery keypress 事件对象 keyCode for firefox 问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FireFox 的 jQuery 按键事件为事件对象提供加密的 keyCode
属性String.fromCharCode(e.keyCode)
转换后但在 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>
推荐答案
您应该在 Firefox 中使用 e.charCode
.
You should use e.charCode
in Firefox.
$("#booter").keypress(function(e){
var code = e.charCode || e.keyCode;
var input = $(this).val() + String.fromCharCode(code);
$('#text').focus().val(input);
return false;
});
在这里试试:
附注如果你想知道为什么会这样:http://www.quirksmode.org/js/keys.html
PS If you're wondering why all this mess: http://www.quirksmode.org/js/keys.html
这篇关于jquery keypress 事件对象 keyCode for firefox 问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文