堆疊開發人員,我試圖了解為什么或如何正確切換表單上的提交按鈕。
這是我的html:
<form id="fs-frm" name="simple-contact-form" accept-charset="utf-8" action="https://formspree.io/f/mlevbeon"
method="post">
<table WIDTH="50%">
<tr>
<tD><label for="full-name">Full Name *</label></td>
<tD><input type="text" name="name" id="full-name" placeholder="First and Last" required></th>
</tr>
<tr>
<td><label for="email-address">Email Address *</label></td>
<td><input type="email" name="_replyto" id="email-address"
placeholder="[email protected]" required></td>
</tr>
<tr>
<td><label for="message">Message *</label></td>
<td><textarea rows="10" name="message" id="message" placeholder="" required></textarea></td>
</tr>
<tr>
<td><label for="input-file">Input File Here - </label></td>
<td><input type="file"></td>
</tr>
<tr>
<input type="hidden" name="_subject" id="email-subject" value="Contact Form Submission">
<td></td>
<td><input id="submit" type="submit" value="submit" ></td>
</tr>
</table>
</form>
這是我的js:
const submitbutton = draft_2.getElementById("submit");
const input = draft_2.getElementById("full-name", "email-address", "message")
input.addEventListener("keyup", (e) => {
const value = e.currentTarget.value;
submitbutton.disabled = false;
if (value === "") {
submitbutton.disabled = true;
}
})
我已經在我的 VSC 上正確地從一個到另一個呼叫了它們,但我認為 js 并沒有真正做任何事情。
uj5u.com熱心網友回復:
不確定 draft_2 是什么,所以在這里用檔案替換它。否則向我們展示draft_2 的定義位置。
const submitbutton = document.getElementById("submit");
const inputs = document.querySelectorAll("#fs-frm input, #fs-frm textarea");
inputs.forEach((input) => {
input.addEventListener("keyup", (e) => {
const value = e.currentTarget.value;
if (value === "") {
submitbutton.disabled = true;
} else {
submitbutton.disabled = false;
}
});
});
并使按鈕默認禁用
<input disabled id="submit" type="submit" value="submit" >
uj5u.com熱心網友回復:
您可以為按鈕提供“禁用”引數,然后在“切換”功能中,您可以對它進行判斷。我認為它會起作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/513589.html
下一篇:如何防止輸入復選框受空格鍵影響?
