onclick事件中checkForm()和return checkForm()的区别

好久不见. 提交于 2019-12-06 11:20:12

先上代码:

<!DOCTYPE html>
<html>
<head>
    <title>test</title>
</head>
<body>
    <div>
        <a href="www.baidu.com" onclick="return checkForm()">点击我</a>
    </div>
</body>
</html>
<script type="text/javascript">
    function checkForm()
    {
        return true;
    }
</script>

测试结果:测试发现,onclick里加return时,checkForm()方法必须返回true才可以触发a标签的跳转。而不加return的时候,无论checkForm()返回false还是true,都会触发a标签的跳转。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!