The role of return in JavaScript

Source: Internet
Author: User

  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:
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.