Javascript HTML/JS表单提交两次
我正在使用node.js/express创建一个网页 我现在有一个表单,有一些输入,还有一个提交按钮,点击页面上的另一个按钮就会触发这个按钮 这是我表格的代码:Javascript HTML/JS表单提交两次,javascript,html,node.js,forms,submit,Javascript,Html,Node.js,Forms,Submit,我正在使用node.js/express创建一个网页 我现在有一个表单,有一些输入,还有一个提交按钮,点击页面上的另一个按钮就会触发这个按钮 这是我表格的代码: <form name= "form" id="form-id" action="http://localhost:1337/process_post" method="POST"> <input type="hidden" name="hiddentext" id="textarea"/> <
<form name= "form" id="form-id" action="http://localhost:1337/process_post" method="POST">
<input type="hidden" name="hiddentext" id="textarea"/>
<input hidden type="submit" name="submitbutton" id="submit_button"/>
</form>
我遇到的问题是,表格提交了两次。我不确定为什么会发生这种情况,以及如何解决这个问题。有什么提示吗?您需要在
onclick
属性中返回false
,以防止默认操作,即提交表单(您已经在做)。像这样:
<INPUT type="button" id="button-id" value="Save" onclick="this.disabled=true;load_page('form-id');return false;" />
您的意思是函数加载页面(formId){document.getElementById(“提交按钮”)。单击(函数(){return false;})},因为这不起作用
function load_page(formId){
document.getElementById("submit_button").click();
}
<INPUT type="button" id="button-id" value="Save" onclick="this.disabled=true;load_page('form-id');return false;" />