按键事件在Mozilla Firefox中无效 [英] Key press event is not working in Mozilla Firefox

查看:132
本文介绍了按键事件在Mozilla Firefox中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按键事件在Mozilla Firefox中无效。
我已经动态创建了一个带有文本boix的表行,并且该文本框也有一个按键事件。

Key press event is not working in Mozilla Firefox. I have create a table row dynamically with a text boix in it and that text box has a key press event too.

  var el = document.createElement('input');
           el.type = 'text';
           el.name = 'suggest2';
             el.setAttribute("id",str2); 

             el.setAttribute("onkeypress","additemifenter(this.id)"); 
 cell2.appendChild(el);
row.appendChild(cell2);

在谷歌浏览器中,调用additemifenter(this.id)函数。但在Firefox中,该功能没有被执行。在Firefox中执行此操作的替代方法是什么?

In google chrome the function additemifenter(this.id) is called. But in firefox that function is not getting executed. What is the alternate way to do this in firefox?

推荐答案

也许最后的分号会有所帮助

Maybe the semicolon at the end would help

el.setAttribute("onkeypress","additemifenter(this.id);");

但是

你为什么不呢?使用标准事件处理模型:

why don't you use the standard event handling model:

el.onkeypress = function(event){
// functionality
};

el.addEventListener("keypress",function(event){ 
// functionality
},false);

检查密钥代码必须使用代码:

to check the keycode you must use the code:

var code = (event.keyCode) ? event.keyCode : event.which;

if(code == 13){

}

这篇关于按键事件在Mozilla Firefox中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆