Thuộc tính disabled của đối tượng Input Time trong HTML DOM thiết lập hoặc trả về trạng thái vô hiệu hóa của ô nhập giờ. Khi disabled, ô không nhận tương tác, không gửi giá trị khi submit form, thường hiển thị mờ (xám).
Cú pháp
Lấy giá trị boolean
inputTimeObject.disabled
Thiết lập disabled
inputTimeObject.disabled = booleanValue
Các giá trị boolean
| booleanValue | Chi tiết |
|---|---|
| true | Ô time bị vô hiệu hóa. |
| false | Ô time hoạt động bình thường (mặc định). |
Ví dụ minh họa
Form hẹn giờ: cho chọn giờ, nhấn "Xác nhận" sẽ khóa ô time (disabled = true):
<!DOCTYPE html>
<html>
<head>
<title>Input Time disabled</title>
<style>
form { width: 70%; margin: 0 auto; text-align: center; }
* { padding: 2px; margin: 5px; }
input[type="button"] { border-radius: 10px; }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Time-disabled</legend>
<label for="TimeSelect">Giờ hẹn: <input type="time" id="TimeSelect" value="15:10"> </label>
<input type="button" onclick="xacNhanHen()" value="Xác nhận hẹn">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputTime = document.getElementById("TimeSelect");
function xacNhanHen() {
inputTime.disabled = true;
divDisplay.textContent = 'Hẹn cố định lúc: ' + inputTime.value;
}
</script>
</body>
</html>
Kết quả
- Ban đầu: ô time 15:10 cho chỉnh sửa.
- Nhấn Xác nhận hẹn: ô time bị xám, không thể chỉnh, hiển thị "Hẹn cố định lúc: 15:10".
Khác biệt readOnly vs disabled: disabled không gửi giá trị khi submit form, không focus được. readOnly vẫn gửi giá trị, cho focus/copy.