Thuộc tính bước Thời gian nhập DOM HTML xác định khoảng thời gian hợp pháp chỉ tính bằng giây.
Cú pháp
Sau đây là cú pháp -
- Trả lại giá trị số
inputTimeObject.step
- Bước thiết lập thuộc tính thành một giá trị số
inputTimeObject.step = number
Tham số
Giá trị số tham số -
| giây | các giá trị hợp lệ tạo thành từ những số chia hoàn toàn cho 60 (ví dụ:10,15,20) |
Ví dụ
Hãy để chúng tôi xem ví dụ về bước Thời gian nhập liệu tài sản -
<!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">Time: </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> Đầu ra
Điều này sẽ tạo ra kết quả sau -
Nhấp vào “Bước tới 20” nút -
Nhấp vào “Bước tới 30” nút -