Thuộc tính step của <input type="month"> trả về hoặc thiết lập **bước nhảy** (số tháng) khi người dùng dùng mũi tên lên/xuăng hoặc gọi stepUp()/stepDown(). Mặc định là 1 (1 tháng).
Cú pháp
Lấy giá trị:
monthInput.step
Thiết lập giá trị:
monthInput.step = "so_thang"
Ví dụ: Thay đổi step thành 3 tháng
<!DOCTYPE html>
<html>
<head>
<style>
html, body { height: 100%; margin: 0; font-family: sans-serif; }
body {
text-align: center; color: white;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
}
input[type="month"] {
display: block; width: 35%; margin: 15px auto;
border: 2px solid white; background: transparent;
color: white; font-weight: bold; padding: 8px;
}
.btn {
background: #0197F6; border: none; color: white;
padding: 10px 20px; border-radius: 4px; width: 35%;
margin: 10px auto; display: block; cursor: pointer;
}
.show { font-size: 1.5rem; color: #dc3545; font-weight: bold; margin-top: 15px; }
</style>
</head>
<body>
<h1>Demo Input Month step Property</h1>
<p>Chọn tháng cho kỳ nghỉ</p>
<input type="month" class="monthInput">
<button onclick="setStep3()" class="btn">Đặt Step = 3 tháng</button>
<button onclick="showStep()" class="btn">Xem giá trị Step</button>
<div id="result" class="show"></div>
<script>
function setStep3() {
document.querySelector(".monthInput").step = "3";
}
function showStep() {
var step = document.querySelector(".monthInput").step;
document.getElementById("result").textContent = "Step hiện tại = " + step + " tháng";
}
</script>
</body>
</html>
Kết quả
Ban đầu (step=1):

Sau khi đặt Step = 3 - các mũi tên tăng/giảm nhảy 3 tháng:


⚠️ Lưu ý:
stepảnh hưởng đến UI spinner (mũi tên) và phương thứcstepUp/Down.- Kết hợp với
min/max: giá trị phải = min + n*step. - VD: min="2024-01", step="3" → các giá trị hợp lệ: 01, 04, 07, 10...