Home > Web Front-end > JS Tutorial > body text

Use jquery to click the Enter key to achieve the login effect (detailed tutorial)

亚连
Release: 2018-05-31 14:54:25
Original
2302 people have browsed it

Below I will share 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.

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.

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:

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Detailed tutorial on using Angular CLI to generate Angular 5 projects

##Analysis of javascript prototype and prototype chain

jquery realizes the function of dragging file upload loading progress bar

##

The above is the detailed content of Use jquery to click the Enter key to achieve the login effect (detailed tutorial). 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!