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: