js 回车提交

来源:互联网 发布:福州橙子网络 编辑:程序博客网 时间:2024/05/22 16:38
    1、JavaScript 方法:    [javascript] <script>         document.onkeydown=function(event){             e = event ? event :(window.event ? window.event : null);             if(e.keyCode==13){                 //执行的方法                  alert('回车检测到了');             }         }     </script>     <script>     document.onkeydown=function(event){      e = event ? event :(window.event ? window.event : null);      if(e.keyCode==13){       //执行的方法       alert('回车检测到了');      }     }    </script>    2、jQuery 方法:    [javascript] <script>         $(document).ready(function(){             $("按下回车的控件").keydown(function(e){                 var curKey = e.which;                 if(curKey == 13){                     $("#回车事件按钮控件").click();                     return false;                 }             });         });     </script>