Javascript firefox问题的jquery keypress事件对象keyCode?
FireFox的jQuery keypress事件为事件对象提供加密的Javascript firefox问题的jquery keypress事件对象keyCode?,javascript,jquery,events,keypress,keycode,Javascript,Jquery,Events,Keypress,Keycode,FireFox的jQuery keypress事件为事件对象提供加密的keyCode属性 在String.fromCharCode(e.keyCode)转换后,可以在Chrome中完美工作 以下是javascript代码: <!-- #booter and #text are ids of html element textarea --> <script type="text/javascript"> $(function(){
keyCode
属性
在String.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>
$(函数(){
$('#booter')。按键(函数(e){
var input=$(this.val()+String.fromCharCode(e.keyCode);
$('#text').focus().val(输入);
返回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;
});
请在此处尝试:
PS
如果你想知道为什么会这样混乱:它对IE和FF都有效
$(document).ready(function (){
$('#txtEntry').keypress(function (e) {
$('#lnkValidEdit').focus();
return false;
});
工作得很有魅力。。。谢谢:)e.charCode | | e.keyCode请注意,根据MDN,e.keyCode、e.charCode和e.已弃用。我有点惊讶,因为称为e.code的替换没有适当的支持。现在唯一的选择似乎是拥有IE9支持的e.key