In-depth understanding of the role of return in javascript _ basic knowledge

Source: Internet
Author: User
This article mainly introduces the function of return in javascript. If you need it, you can refer to the return here for details:

For example, the difference between onClick = 'Return add_onclick () 'and onClick = 'add _ onclick ()'

When JAVASCRIPT calls a function in an event, the return value is actually used to set window. event. returnvalue.

This value determines whether the current operation continues.
If true is returned, the operation continues.
If the return value is false, the operation is interrupted.

Directly execute (no return is required ). Window. event. returnvalue will not be set
Therefore, the Operation will continue by default.

Details are as follows:
For example:
In Open
If the add_onclick () function returns true, the page will open abc.htm
Otherwise, (false is returned), the page will not jump to abc.htm, only the content in your add_onclick () function will be executed. (except for the control page in the add_onclick function to go to abc.htm

)
While Open
No matter what value is returned by add_onclick (), the page abc.htm will be opened after add_onclick is executed.

In addition:
Onclick event is equivalent to onclick = "return true/false"
Example:

The Code is as follows:


Function check ()
{
If (obj. value = "")
{
Window. alert ("cannot be blank! ");
Obj. focus ();
Return false;
}
Return true;
}


The form is submitted only when the call method returns true. Otherwise, the form is not submitted. This is the submit button.
Bytes ------------------------------------------------------------------------------------------

Return is not required to call js functions, but the form cannot be submitted. Therefore, add a sentence to the js function.
Example:

The Code is as follows:


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.