This article mainly introduces the role of return in JavaScript, the need for friends can refer to the
This return contains some details: For example: onclick= ' return Add_onclick () ' and onclick= ' Add_onclick () ' Difference When JavaScript calls a function in an event, returning the value with return is actually setting the Window.event.returnvalue. This value determines whether the current operation continues. When True is returned, the operation continues. When the return is false, the operation is interrupted. Direct Execution (no return). The window.event.returnvalue will not be set so the operation will continue by default details are as follows: For example, when <a href= "abc.htm" onclick= "return Add_onclick ()" >Open</a> if the function Add_onclick () returns True, the page will open abc.htm otherwise, (return false), then the page will not jump to abc.htm, will only execute your Add_onclick () The content in the function. (The Add_onclick function controls the page to go to abc.htm except ) and <a href= "abc.htm" onclick= "Add_onclick ()" >Open</a> no matter add_ OnClick () returns what value, will open the page after executing Add_onclick abc.htm Additional: The onclick event is equivalent to onclick= "return True/false" Example: Copy code code as follows: function check () {if (obj.value== "") { window.alert ("cannot be empty!") "); obj.focus (); return false; &NBSP} return true; The Call method returns True before the form is submitted, but not if it is not submitted, which is the submit button------------------------------------------------------------------------------------------ Call JS function does not need to return, But the form cannot be submitted, so add a sentence to the JS function: The code is as follows: <script language= "JavaScript" > function check () {if (obj.value== "") { window.alert ("cannot be empty!") "); obj.focus (); return false; &NBSP document.myform.submit (); return true; {</script> Note: Document.myform.submit (); To return true about JavaScript in the pre-return False and return true returns are keywords in JavaScript where functions are returned, and the results of a function can be returned with return, so that the return result can be received with a variable at the point where the function is invoked. Any type of variable data or expression within the return keyword can be returned, or even nothing returned, such as the code as follows: function Nullreturn (IsNull) {if (isnull==true) { Return } This is also true, meaning that returns null (NULL) so sometimes the return action is used to terminate the function execution. For example, the code is as follows: