Phương thức stepDown() của <input type="month"> **giảm** giá trị tháng xuống một số lượng xác định. Nếu bỏ qua tham số, mặc định giảm 1 tháng.
Cú pháp
monthInput.stepDown(number)
number (tùy chọn): Số tháng muốn giảm. Mặc định = 1.
Ví dụ: Tăng/giảm tháng (cùng demo stepUp)
<!DOCTYPE html>
<html>
<head>
<title>Demo stepUp()/stepDown() Month</title>
<style>
body { text-align: center; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat; height: 100vh; color: white; font-family: sans-serif; }
p { font-size: 1.5rem; }
input[type="month"] { width: 40%; padding: 8px; }
button {
background-color: #dc3545; color: white; padding: 8px 16px;
border: none; width: 140px; margin: 10px; border-radius: 25px;
outline: none; cursor: pointer; font-weight: bold;
}
</style>
</head>
<body>
<h1>Demo stepUp()/stepDown() Month</h1>
<p>Chọn tháng sinh của bạn</p>
<input type="month" id="monthInput">
<br><br>
<button onclick="incMonth()">Tăng tháng (stepUp)</button>
<button onclick="decMonth()">Giảm tháng (stepDown)</button>
<script>
function incMonth() { document.getElementById("monthInput").stepUp(); }
function decMonth() { document.getElementById("monthInput").stepDown(); }
</script>
</body>
</html>
Kết quả
Ban đầu:

Nhấn các nút tăng/giảm:


⚠️ Lưu ý:
stepUp() và stepDown() **tuân thủ** các ràng buộc min, max, step. Nếu vượt quá giới hạn, giá trị sẽ dừng tại min/max.