-1
由於某種原因,我的JS沒有按照我的想法反應。 提交按鈕在頁面加載時被禁用。JS檢查是否存在值
當在數據字段中輸入值時,類應該改變並且應該啓用提交按鈕。兩者都沒有發生。
這似乎是一個標準的代碼,但仍然是一個問題?
window.onload = function() {
document.getElementById('form_submit').disabled = true;
}
function validate() {
if (document.getElementById('datum').value == false) {
document.getElementById('div_datum').className = "col-md-2 input-group has-warning";
} else {
document.getElementById('div_datum').className = "col-md-2 input-group has-success";
document.getElementById('form_submit').disabled = false;
}
}
<div class="container">
<div class="form-group row">
<label for="datum" class="col-md-2 form-label">Datum toolbox</label>
<div class="col-md-2 input-group has-warning" id="div_datum">
<input type="text" class="form-control datepicker" id="datum" name="datum" onkeyup="validate()" onclick="validate()"><span class="input-group-addon"><span class="glyphicon glyphicon-remove" aria-hidden="true" data-toggle="tooltip" title="Verplicht veld"></span></span>
</div>
</div>
<button type="submit" class="btn btn-primary" id="form_submit">Verstuur</button>
</div>
我已將您的代碼塊轉換爲Stack Snippet。當我在字段中輸入時,它會啓用按鈕。你能澄清問題是什麼嗎? –
你怎麼隱藏按鈕?您的示例中沒有任何內容隱藏或顯示按鈕。 –