jquery clicks the enter key to achieve login effect example sharing

小云云
Release: 2018-03-12 10:14:18
Original
1787 people have browsed it

When I was doing project login recently, I had to click the login button every time to enter the corresponding page, which gave the user a very bad experience, so I added the use of the Enter key to log in. This article mainly shares with you a jquery method of clicking the Enter key to achieve the login effect and default focus. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.

Method:

<form> 
<input type="text" id="username_txt" placeholder="用户名" />
<input type="password" id="userpass_txt" placeholder="密码" />
    <button id="login_btn">登录</button>
</form>
$(function () { 
$(&#39;#username_txt&#39;).focus();
    //用户点击按钮
    $("#login_btn").click(function () {
    //获取用户名
    var username = $(&#39;#username_txt&#39;).val();
    //获取密码
    var userpass = $(&#39;#userpass_txt&#39;).val();
     if (username == "" || userpass == "") { alert("用户名密码不能为空!"&#39;); }
    else {
//调用登录方法
        $.ajax({
           
 });
 }
 });
$("body").keydown(function(event) {
 if (event.keyCode == "13") {//keyCode=13是回车键
$("#login_btn").click();
 }
}); 
});
Copy after login

Final rendering:

##Related recommendations:


jquery Enter key trigger event implementation method

Analyze the differences between input submit, button and enter key to submit data

Detailed explanation of input submit, button and enter key to submit data

The above is the detailed content of jquery clicks the enter key to achieve login effect example sharing. For more information, please follow other related articles on the PHP Chinese website!

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