Thuộc tính kiểu Thời gian nhập DOM HTML trả về / đặt loại Thời gian nhập liệu.
Cú pháp
Sau đây là cú pháp -
- Giá trị chuỗi trả về
inputTimeObject.type
- Đặt loại thành giá trị chuỗi
inputTimeObject.type = stringValue
Giá trị chuỗi
Đây, “stringValue” có thể như sau -
| stringValue | Chi tiết |
|---|---|
| thời gian | Nó xác định loại đầu vào là thời gian |
| datetime-local | Nó xác định loại đầu vào là datetime-local |
| hộp kiểm | Nó xác định loại đầu vào là hộp kiểm |
| text | Nó xác định loại đầu vào là văn bản |
Ví dụ
Hãy để chúng tôi xem ví dụ về Loại thời gian nhập liệu tài sản -
<!DOCTYPE html>
<html>
<head>
<title>Input Time type</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-type</legend>
<label for="TimeSelect"></label>
<input type="time" id="TimeSelect">
<input type="button" onclick="getTypeOfInput()" value="What input is expected?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var labelDisplay = document.querySelector("label");
var divDisplay = document.getElementById("divDisplay");
var inputTime = document.getElementById("TimeSelect");
function getTypeOfInput() {
labelDisplay.textContent = 'Time: ';
divDisplay.textContent = 'Input of type time (hh:mm:ss.ms) is expected';
}
</script>
</body>
</html> Đầu ra
Điều này sẽ tạo ra kết quả sau -
Trước khi nhấp vào ‘Đầu vào nào được mong đợi?’ nút -
Sau khi nhấp vào ‘Đầu vào nào được mong đợi?’ nút -