Home > Web Front-end > JS Tutorial > Example of return usage in JavaScript

Example of return usage in JavaScript

高洛峰
Release: 2016-12-03 15:26:23
Original
1122 people have browsed it

The examples in this article describe the usage of return in JavaScript. Share it with everyone for your reference, the details are as follows:

return can accept the return value in the function, provided that there is a return statement in the function.

The following is a small application example:

<html>
 <head>
  <script type=&#39;text/javascript&#39;>
   function linkPage(){
    alert(&#39;You Clicked??&#39;);
    return false;
   }
  </script>
 </head>
 <body>
  <A href=&#39;http://www.baidu.com&#39; name=&#39;link&#39; onclick="return linkPage()">
   Click Me
  </A>
 </body>
<html>
Copy after login

This example is very simple. If you click Click Me, an onclick event will be triggered. The onclick event calls the linkPage function and accepts its return value.

The page will pop up an alert prompt box and accept the return value of linkPage. If the value is true, it will jump to the Baidu page, but the return value is false, so there is no movement on the page.

Sometimes this return is unnecessary, presence and absence are the same effect. That is, when the function linkPage has no return value.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template