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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM