jquery Click Enter to achieve the login effect instance sharing

Source: Internet
Author: User
Recently in the project login, every time you need to click the login button to access the corresponding page, to give users a very bad experience, so I added the use of ENTER to achieve login. This article is mainly for you to share a jquery hit Enter to achieve the login effect and the default focus of the method, with a good reference value, I hope to help you. Follow the small series together to see it, hope to help everyone.

Method:

<form> <input type= "text" id= "Username_txt" placeholder= "user name"/><input type= "password" id= "Userpass_ TXT "placeholder=" password "/>    <button id=" login_btn "> Login </button></form>$ (function () {$ (' # Username_txt '). focus ();    The user clicks    the button $ ("#login_btn"). Click (function () {    //Get username    var username = $ (' #username_txt '). Val ();    Get the password    var userpass = $ (' #userpass_txt '). Val ();     if (username = = "" | | Userpass = = "") {alert ("Username password cannot be empty! "'); }    else {//Call login method        $.ajax ({            });}}); $ ("Body"). KeyDown (function (event) {if (Event.keycode = = ") {//keycode=13 is a return $ (" #login_btn "). Click ();}); });

Eventually:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.