input框回车事件

来源:互联网 发布:林彪军事才能 知乎 编辑:程序博客网 时间:2024/05/29 02:40

 <input id="inputId" type="text" />

<script>

//方法1
    $(function(){  
     $('#inputId').bind('keypress',function(event){  
        if(event.keyCode == "13"){
           alert();
        }  
    });  
  });  

//方法2

   $('#inputId').on('keypress',function(event){ 
         if(event.keyCode == 13) {  
             alert();  
         }  
     });

//方法3

  $("#inputId").keydown(function(e) {  
           if (e.keyCode == 13) {  
                  alert("12345....");
           }  
      }); 

</script>



原创粉丝点击