Home >Web Front-end >JS Tutorial >Detailed explanation and example code of jquery implementation of carriage return login

Detailed explanation and example code of jquery implementation of carriage return login

高洛峰
高洛峰Original
2016-12-09 13:13:011051browse

jquery implements enter login

1. button button submission method

//按钮事件
$(‘#btnSumit‘).click(function() {
  alert(‘测试‘);
});
 //回车提交事件
$("body").keydown(function() {
  if (event.keyCode == "13") {//keyCode=13是回车键
    $(‘#btnSumit‘).click();
  }
});

2. form submission method

  a. Use jquery

$("body").bind(‘keyup‘,function(event) {
  if(event.keyCode==13){
    document.form.submit();
  }  
});

b. Non-jquery

<body onkeyup="autosubmit()">//添加监听事件
function autosubmit(){//事件触发函数
 if(event.keyCode==13){
   document.form.submit();
 }  
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn