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

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

以下是javascript代码:

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

您应该在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; });