背景
页面加载后,会有支付按钮,点击该按钮将在调用 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>
问题 如何让页面加载并提交reponse.php时自动调用“onSubmit=”return pay(this)”?
我尝试将以下代码放在 html 文件的末尾。
<script type='text/javascript'>
document.ini.submit();
</script>
这行为不正确,似乎“pay(this)”没有正确加载。
最佳答案
这应该有效
<script>
window.onload=function(){
document.getElementById('ini').submit();
}
</script>
这将通过触发提交事件中的函数来触发表单上的提交事件。
关于javascript - html页面自动提交 - javascript填充隐藏字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17802475/