最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Key press event is not working in Mozilla Firefox - Stack Overflow

programmeradmin6浏览0评论

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);

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?

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);

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?

Share Improve this question edited Mar 2, 2017 at 8:48 Smile4ever 3,7243 gold badges28 silver badges34 bronze badges asked Jun 4, 2011 at 8:38 VaradaVarada 17.2k13 gold badges51 silver badges70 bronze badges 1
  • duplicate: stackoverflow./questions/95731/… – davin Commented Jun 4, 2011 at 8:54
Add a ment  | 

1 Answer 1

Reset to default 6

Maybe the semicolon at the end would help

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

but

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

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

or

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){

}
发布评论

评论列表(0)

  1. 暂无评论