【问题标题】:html page submit automatically - javascript fills hidden fieldhtml页面自动提交 - javascript填充隐藏字段
【发布时间】:2013-07-22 01:37:10
【问题描述】:

背景

页面加载后,会有支付按钮,点击按钮会在pay(this) javascript方法调用后触发表单提交。

点击提交按钮时,会调用return pay(this),填充更多隐藏字段,然后提交到response.php。

<form id=ini method=post action="response.php" onSubmit="return pay(this)">
..
..
hidden fields - some of them are filled with value from get values of the previous page
..
..
<input type=submit>
</form>

问题 如何让页面在页面加载完成后自动调用“onSubmit="return pay(this)”?

我尝试将下面的代码放在 html 文件的末尾。

<script type='text/javascript'>
document.ini.submit();
</script>

这不正确,似乎“pay(this)”没有正确加载。

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    这应该可以工作

    <script> 
    window.onload=function(){ 
           document.getElementById('ini').submit(); 
    } 
    </script>
    

    这将通过触发提交事件中的函数来触发表单上的提交事件。

    【讨论】:

    • .submit() 没有调用 的“return pay(this)”,我该怎么做呢?
    • 是 onsubmit 的错误用法。而是在
      标签上添加 onsubmit 事件,例如
      这应该可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 2015-10-25
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    相关资源
    最近更新 更多