美文网首页
阻止form表单提交

阻止form表单提交

作者: 青椒rose炒饭 | 来源:发表于2019-04-13 22:43 被阅读0次

今天为这个小问题折腾了好些时间,在form表单的onsubmit事件内返回一个false就行了。这个返回并不是在函数内返回我就是错在了这个地方。onsubmit属性的值也需要有一个return,不然是不会成功的。

代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <script type="text/javascript">
        function blockSubmit(){
            return false;
        }
    </script>
    <body>
        <form action="http://localhost" method="post" onsubmit="return blockSubmit()">
            <input type="text" />
            <input type="password" />
            <input type="submit" value="提交" />
            
        </form>
    </body>
</html>

相关文章

网友评论

      本文标题:阻止form表单提交

      本文链接:https://www.haomeiwen.com/subject/hjrdwqtx.html