Understanding of function return False in JavaScript (instance code)

Source: Internet
Author: User

1. Common code, registering an event method on a DOM node

$ ("#btnResponse"). Click (Login); $ ("#txtCode"). KeyDown (Returnkey);

2. Very normal login function, just inside with the Swal plugin

Code execution effect is what I want, click Btnresponse, when meet trigger condition, pop up Swal prompt box, very good.

functionLogin (e) {varLoginuserid = $ ("#txtUserno"). Val ();//User name    varPassWord = $ ("#txtPassword"). Val ();//Password    varPcode = $ ("#txtCode"). Val ();//Graphics Verification Code    //Verify required Fields    if(Loginuserid = = =NULL|| Loginuserid.trim () = = = ""{Swal ({title:Failed, Text:"Account cannot be empty", type:"Warning", Showcancelbutton:true, Confirmbuttoncolor:"#DD6B55", Confirmbuttontext:Determine, Closeonconfirm:false        }); return false; }    //A little ...

3. Do not achieve the desired effect of the Returnkey method design, pop-up Swal prompt brush off immediately, see the difference between login and Returnkey, nothing but returnkey and set a layer, and then call the login method

function Returnkey (event) {    if (event.keycode = =){       Login ();    }}

Description: Analysis of the above code, returnkey after the completion of login, Returnkey where the execution thread has continued execution, so Swal was brushed off.

4. Change the code to achieve the desired effect, after the carriage return, the Swal pop-up box stays on the page.

function Returnkey (event) {    if (Event.keycode = =) {       return Login ();   Login (); return false;     }}

Understanding of function return False in JavaScript (instance code)

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.