当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js与jquery回车提交的方法教程

js与jquery回车提交的方法教程

2019年03月31日  | 移动技术网IT编程  | 我要评论

本文实例讲述了js与jquery回车提交的方法。分享给大家供大家参考。具体如下:

1、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 方法:

<script> 
  $(document).ready(function(){ 
    $("按下回车的控件").keydown(function(e){ 
      var curkey = e.which; 
      if(curkey == 13){ 
        $("#回车事件按钮控件").click(); 
        return false; 
      } 
    }); 
  }); 
</script>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网