input框触发回车事件

Posted 大道至简

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了input框触发回车事件相关的知识,希望对你有一定的参考价值。

window.event只能在IE下运行,不能在firefox下运行,这是因为firefox的event只能在事件发生的现场使用。   
在firefox里直接调用event对象会报undefined。
兼容解决方式:

 1 <input type="text" onkeydown="keyup_submit(event);">
 2 
 3 <script>
 4 function keyup_submit(e){ 
 5  var evt = window.event || e; 
 6   if (evt.keyCode == 13){
 7     //回车事件
 8   }
 9 }
10 </script>

 



*firefox需要传递event对象,书写必须为event

以上是关于input框触发回车事件的主要内容,如果未能解决你的问题,请参考以下文章