Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính form của HTML DOM Input Week

Thuộc tính form của đối tượng Input Week trong HTML DOM trả về tham chiếu đến đối tượng Form chứa ô chọn tuần/năm. Dùng để truy xuất thông tin form cha từ phần tử con.

Cú pháp

Lấy tham chiếu form

inputWeekObject.form

Ví dụ minh họa

Ô week nằm trong form id="Mid-Term". Nhấn nút lấy tên kỳ thi từ form.id:

<!DOCTYPE html>
<html>
<head>
<title>Input Week 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="Mid-Term">
  <fieldset>
    <legend>Week-form</legend>
    <label for="WeekSelect">Tuần thi: <input type="week" id="WeekSelect" value="2019-W36"> </label> 
    <input type="button" onclick="hienThiKyThi()" value="Kỳ thi nào tuần này?"> 
    <div id="divDisplay"></div> 
  </fieldset> 
</form> 
<script> 
  var divDisplay = document.getElementById("divDisplay"); 
  var inputWeek = document.getElementById("WeekSelect"); 
  function hienThiKyThi() { 
    divDisplay.textContent = 'Kỳ thi: ' + inputWeek.form.id; 
  } 
</script> 
</body> 
</html>

Kết quả

  • Ban đầu: ô week 2019-W36.
  • Nhấn Kỳ thi nào tuần này?: "Kỳ thi: Mid-Term".

Ứng dụng: Xác định form chứa input khi có nhiều form trên trang, hoặc submit form qua inputWeek.form.submit().