13三、js中return、return result、return true、 return false

来源:https://blog.csdn.net/q3254421/article/details/83154247
1、正常状况
<!DOCTYPE html>
<html>
<head>
    <title>return测试</title>
</head>
<body>
    <a href="#"></a>
    <a onclick="fun1()">111</a>
    <a onclick="fun2()">222</a>
    <a onclick="fun3()">333</a>
    <a onclick="fun4()">444</a>
    <script type="text/javascript">
        function fun1() {
            return;
        }
        function fun2() {
            return false
        }
        function fun3() {
            return true
        }
        console.log(fun1())
        // undefined
        console.log(fun2())
        // false
        console.log(fun3())
        // true
    </script>
</body>
</html>
经过上面的例子 能够看出return;return false;return true在函数内部都中断了函数的执行

2、异常状况(表单提交)
1. return ;  return false  return true 都会在函数内部阻止程序的执行。
2. 只有 return false 会阻止表单的提交。
相关文章
相关标签/搜索