码迷,mamicode.com
首页 > 其他好文 > 详细

input框触发回车事件

时间:2016-08-26 09:10:44      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

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框触发回车事件

标签:

原文地址:http://www.cnblogs.com/houweijian/p/5808978.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!