【发布时间】:2021-07-28 11:38:02
【问题描述】:
我有两个带有两个单独的 onclick submit() 按钮的表单。问题是,无论 ID 是什么,只有第一个表单被发送出去。我尝试使用 getElementByClassName 和 Tagname 以及为表单提供不同的名称,但仍然无法正常工作..
<script>
function submitForm() {
document.getElementById("formDelay").submit()
}
document.getElementById('formDelayButton').onclick = function() {
setTimeout(submitForm, 900);
};
function submitForm1() {
document.getElementById("formDelay1").submit()
}
document.getElementById('formDelayButton1').onclick = function() {
setTimeout(submitForm, 900);
};
</script>
<% if(userSecrets.length != 0){ %>
<p>My shared secrets</p>
<form action="/mysecrets/delete" method="POST" id="formDelay1">
<div class="form-group">
<select class="form" name=" secret">
<% userSecrets.forEach(function(secret){ %>
<option value="<%= secret %>"><%= secret %></option>
<% }); %>
</select>
</form>
<button type="submit" class="button" id="formDelayButton1">Delete Secret</button>
<% } %>
<% if(userSecrets.length == [] ){ %>
<p>You haven`t shared any of your secrets yet. <br> This is the perfect time to do so!</p>
<% } %>
<form action="/mysecrets" method="POST" id="formDelay">
<div class="form-group">
<input type="text" class="form" name="secret" placeholder="What's your secret?">
</div>
</form>
<button type="submit" id="formDelayButton" class="button">share it
</button>
【问题讨论】:
-
你有两个函数
submitForm和submitForm1但你总是使用submitForm。
标签: javascript html forms ejs