คุณสมบัติ step ของ HTML DOM Input Time กำหนดช่วงเวลาที่ถูกต้องสำหรับวินาที (legal intervals) ในช่องป้อนเวลา
ไวยากรณ์ (Syntax)
การดึงค่า step
inputTimeObject.step
การกำหนดค่า step
inputTimeObject.step = number
พารามิเตอร์ (Parameters)
| seconds | ค่าที่ถูกต้องคือตัวเลขที่หาร 60 ลงตัว (เช่น 10, 15, 20, 30, 60) |
ตัวอย่างการใช้งาน
ตัวอย่างเปลี่ยนค่า step ของช่องเวลา
<!DOCTYPE html>
<html>
<head>
<title>Input Time step</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-step</legend>
<label for="TimeSelect">เวลา: </label>
<input type="time" id="TimeSelect" step="2">
<input type="button" onclick="changeStep(20)" value="Step to 20">
<input type="button" onclick="changeStep(30)" value="Step to 30">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputTime = document.getElementById("TimeSelect");
divDisplay.textContent = 'The current step is: ' + inputTime.step;
function changeStep(myStep) {
inputTime.step = myStep;
divDisplay.textContent = 'The current step is: ' + inputTime.step;
}
</script>
</body>
</html>
ผลลัพธ์
เริ่มต้น - step = 2 (วินาที)
คลิก "Step to 20" - step = 20 วินาที (UI จะเพิ่ม/ลดทีละ 20 วินาที)
คลิก "Step to 30" - step = 30 วินาที (UI จะเพิ่ม/ลดทีละ 30 วินาที)
ผลกระทบต่อ UI: ค่า step ส่งผลต่อปุ่มลูกศรขึ้น/ลงในบราว์เซอร์ที่รองรับ และการตรวจสอบความถูกต้อง (validation)