【问题标题】:Submit form automatically [duplicate]自动提交表格[重复]
【发布时间】:2018-07-03 04:37:12
【问题描述】:

谁能帮帮我

我想在页面加载时自动提交表单是否可以做到?

<form method='post' action='/delete-account.php'>
<input type="submit" id="submit" name="submit" value="Confirm Account Removal" /></form>

【问题讨论】:

    标签: javascript php html forms submit


    【解决方案1】:
    <form method='post' name="myForm" id="myForm"  action='/delete-account.php'>
    <input type="submit" id="submit" name="submit" value="Confirm Account Removal" /></form>
    
     window.onload=function(){
              document.forms["myForm"].submit();
     }
    

    【讨论】:

    • 我试了一下,没用
    • 你有什么错误吗??
    • 谢谢!但我现在让它工作了我添加/编辑 document.getElementById("submit").click();
    • 祝你有美好的一天
    【解决方案2】:

    您可以使用 jquery 以这种方式提交

    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
           document.getElementById("myDataForm").submit();
    });
    </script>
    </head>
    <body>
    <form method='post' id="myDataForm" name="myDataForm" action='/delete-account.php'>
    <input type="submit" id="submit" name="submit" value="Confirm Account Removal" /></form>
    </body>
    </html>
    

    请试试这个。

    【讨论】:

    • 不幸的是它没有用,但感谢您的帮助/快速回复
    • 看看问题标签,他没有提到jquery
    • @MikeJones 请尝试现在我已经更改了答案。肯定会奏效
    • 不,那也没用
    猜你喜欢
    • 2017-07-22
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多