本文介绍了onsubmit返回false无效,表格仍提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码

 < html>< head>< script>功能测试() {返回false;}</script></head>< body>< form method ="post" action ="../test.php"><输入类型=提交" onsubmit =返回测试()"></form></body></html> 

表格仍如何提交,对我来说没有意义?

解决方案

您需要停止表单提交,当用户通过以下方式提交表单时:点击,然后点击表格.

submit 按钮的 onsubmit 更改为 onclick

 <输入类型=提交" onsubmit =返回测试()"> 

应该是

 <输入type ="submit" onclick =返回test()"><!-^^^^^^^^^^^^^^^^^^^^^^^^^-> 

如果要使用 onsubmit ,则可以在 form 元素上使用它.

 < form method ="post" action ="../test.php" onsubmit ="return test()"><!-^^^^^^^^^^^^^^^^^^^^^^^^^^->< input type ="submit"/></form> 

This is the code

<html>

    <head>
        <script>
        function test() {
            return false;
        }
        </script>
    </head>

    <body>
        <form method="post" action="../test.php">
            <input type="submit" onsubmit="return test()">
        </form>
    </body>

</html>

how is the form still submitting, it makes no sense to me??

解决方案

You need to stop form submission, when user submits it by clicking the submit button in the form.

Change onsubmit of the submit button to onclick

<input type = "submit" onsubmit= "return test()">

Should be

<input type="submit" onclick="return test()">
<!--                 ^^^^^^^^^^^^^^^^^^^^^^^ -->

If you want to use onsubmit, you can use it on form element.

<form method="post" action="../test.php" onsubmit="return test()">
<!--                                     ^^^^^^^^^^^^^^^^^^^^^^^^ -->
    <input type="submit" />
</form>

这篇关于onsubmit返回false无效,表格仍提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 01:23