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: