Thuộc tính max của đối tượng Input DatetimeLocal lấy hoặc thiết lập ngày giờ cục bộ tối đa cho phép chọn.
Cú pháp
Lấy giá trị (chuỗi)
inputDatetimeLocalObject.max
Thiết lập giá trị
inputDatetimeLocalObject.max = "YYYY-MM-DDThh:mm:ss"
Định dạng chuỗi
| Thành phần | Mô tả |
|---|---|
| YYYY | Năm (ví dụ: 2006) |
| MM | Tháng (01-12, ví dụ: 06) |
| DD | Ngày (01-31, ví dụ: 17) |
| T | Phân tách ngày/giờ |
| hh | Giờ (00-23, ví dụ: 02) |
| mm | Phút (00-59, ví dụ: 21) |
| ss | Giây (00-59, ví dụ: 40) |
Ví dụ minh họa
Gia hạn bảo hiểm bằng cách cập nhật max và đặt value égal max:
<!DOCTYPE html>
<html>
<head>
<title>Input DatetimeLocal max</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>Datetime-Local-max</legend>
<label for="datetimeLocalSelect">Hết hạn bảo hiểm: <input type="datetime-local" id="datetimeLocalSelect" value="2019-07-01T23:59:59" max="2019-08-01T23:59:59" disabled> </label>
<input type="button" onclick="renewInsurance()" value="Gia hạn bảo hiểm">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputDatetimeLocal = document.getElementById("datetimeLocalSelect");
function renewInsurance() {
inputDatetimeLocal.max = '2029-07-01T23:59:59';
inputDatetimeLocal.value = inputDatetimeLocal.max;
divDisplay.textContent = 'Bảo hiểm gia hạn: ' + inputDatetimeLocal.value;
}
</script>
</body>
</html>
Kết quả
Ban đầu trường disabled hiển thị ngày hết hạn cũ. Nhấn "Gia hạn bảo hiểm" cập nhật max và value sang 10 năm sau.