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

高洛峰
Release: 2016-12-09 13:13:01
Original
1050 people have browsed it

jquery implements enter login

1. button button submission method

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

2. form submission method

  a. Use jquery

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

b. Non-jquery

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template