js阻止頁面enter鍵入的事件觸發



<!-- 這一段代碼阻止了當前document中的 enter鍵的 keydown 事件 抄自網絡-->
<script type="text/javascript"> document.onkeydown = function() { var evt = window.event || arguments[0]; if (evt && evt.keyCode == 13) { if (typeof evt.cancelBubble != "undefined") evt.cancelBubble = true; if (typeof evt.stopPropagation == "function") evt.stopPropagation();      return false; } return true; } </script>  

<!-- 更加簡單粗暴的處理 在元素上定義 onkeydown方法 return false; -->
onkeydown="if(event.keyCode==13){return false;}


免責聲明!

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



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