Thuộc tính form của đối tượng Input DatetimeLocal trả về tham chiếu đến phần tử <form> chứa trường datetime-local đó.
Cú pháp
Lấy tham chiếu form
inputDatetimeLocalObject.form
Ví dụ minh họa
Xác định bài thi nào diễn ra vào ngày giờ đã chọn bằng cách đọc form.id:
<!DOCTYPE html>
<html>
<head>
<title>Input DatetimeLocal form</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 id="Mathematics">
<fieldset>
<legend>Datetime-Local-form</legend>
<label for="datetimeLocalSelect">Giờ thi: <input type="datetime-local" id="datetimeLocalSelect" value="2019-09-01T09:00"> </label>
<input type="button" onclick="showExamination()" value="Bài thi nào?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputDatetimeLocal = document.getElementById("datetimeLocalSelect");
function showExamination() {
divDisplay.textContent = 'Bài thi: ' + inputDatetimeLocal.form.id;
}
</script>
</body>
</html>
Kết quả
Nhấn nút để hiển thị ID của form chứa input (ví dụ: "Mathematics").