Phương thức stepDown() của đối tượng Input Week giảm giá trị tuần đi một số tuần xác định. Mặc định giảm 1 tuần nếu không truyền tham số. Dùng cho điều hướng tuần nhanh.
Cú pháp
inputWeekObject.stepDown(số_tuần)
số_tuần(tùy chọn): Số tuần giảm. Mặc định = 1.
Ví dụ minh họa
Ô week ban đầu 2055-W04. Hai nút giảm 2 tuần và 3 tuần:
<!DOCTYPE html>
<html>
<head>
<title>Input Week stepDown()</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>Week-stepDown()</legend>
<label for="WeekSelect">Tuần và Năm: <input type="week" id="WeekSelect" value="2055-W04"> </label>
<input type="button" onclick="doiBuoc('2')" value="Giảm 2 tuần">
<input type="button" onclick="doiBuoc('3')" value="Giảm 3 tuần">
</fieldset>
</form>
<script>
var inputWeek = document.getElementById("WeekSelect");
function doiBuoc(myStep) {
inputWeek.stepDown(myStep);
}
</script>
</body>
</html>
Kết quả
- Ban đầu: 2055-W04.
- Nhấn Giảm 2 tuần: 2055-W02.
- Nhấn Giảm 3 tuần (từ W02): 2054-W52 (quay về năm trước).
Lưu ý: Phương thức tự động xử lý chuyển năm khi tuần < 1 hoặc > 52/53. Tuân thủ ISO 8601.