嘗試根據密碼輸入長度啟用/禁用表單按鈕,但我的代碼不起作用。如果長度小于 15 個字符,則應禁用按鈕。
到目前為止,我的簡單 html 表單
<form class="form" id="form1" method="POST" action="submit.php" accept-charset="UTF-8" autocomplete="off">
<input type="password" placeholder="Password" id="passfield">
<button type="submit" id="form-submit">CONNECT</button>
</form>
在我的情況下不需要用戶名欄位
到目前為止我的Javascript代碼
function submit_btn() {
var field = document.getElementById("passfield");
var button = document.getElementById("form-submit");
if (field.value.lenght < 15){
button.setAttribute("disabled", "");
}else{
button.removeAttribute("disabled");
}
};
uj5u.com熱心網友回復:
你在哪里呼叫 submit_btn?
還有拼寫長度
這里有更好的版本
const field = document.getElementById("passfield");
const button = document.getElementById("form-submit");
field.addEventListener("input", function() {
button.disabled = field.value.length < 15;
})
<form class="form" id="form1" method="POST" action="submit.php" accept-charset="UTF-8" autocomplete="off">
<input type="password" placeholder="Password" id="passfield">
<button type="submit" disabled id="form-submit">CONNECT</button>
</form>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/492750.html
標籤:javascript html 形式 按钮
上一篇:如何使用登錄用戶的憑據從Blazor應用讀取/寫入Azure應用配置中的配置資料?
下一篇:PHP中的按鈕更改編號
