JQuery implements binding click events when the enter key is pressed

  • 2020-03-30 01:29:51
  • OfStack

When the return key is pressed, the event code of binding button click is as follows. By detecting the pressed key value, the return key keycode is 13 to determine whether it is the return key or not, and then the corresponding method is completed.
 
<script> 
$(function(){ 
$(document).keydown(function(event){ 
if(event.keyCode==13){ 
$("#mouse").click(); 
} 
}); 

$("#mouse").click(function(){ 
alert("nihao"); 
}); 
}) 
</script> 

Related articles: