Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

คุณสมบัติ type ของ Input Week ใน HTML DOM

คุณสมบัติ type ของ <input type="week"> ใช้สำหรับอ่านหรือตั้งค่าประเภทของช่องกรอก (ปกติจะเป็น "week" เสมอ)

ไวยากรณ์ (Syntax)

การอ่านค่า

inputWeekObject.type

การตั้งค่า

inputWeekObject.type = stringValue

ค่าสตริงที่เป็นไปได้

stringValueรายละเอียด
weekประเภท input เป็น week (ค่าเริ่มต้น)
datetime-localประเภท input เป็น datetime-local
checkboxประเภท input เป็น checkbox
textประเภท input เป็น text

ตัวอย่างการใช้งาน

ตัวอย่างด้านล่างตรวจสอบประเภทของช่องกรอก:

<!DOCTYPE html>
<html>
<head>
<title>Input Week 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>Week-type</legend>
    <label for="WeekSelect">Event: <input type="week" id="WeekSelect"> </label>
    <input type="button" onclick="getTypeOfInput()" value="What type of input?">
    <div id="divDisplay"></div>
  </fieldset>
</form>
<script>
  var divDisplay = document.getElementById("divDisplay");
  var inputWeek = document.getElementById("WeekSelect");
  
  function getTypeOfInput() {
    divDisplay.textContent = 'Type of input Expected: ' + inputWeek.type;
  }
</script>
</body>
</html>

ผลลัพธ์

ก่อนคลิกปุ่ม: แสดงช่องกรอกสัปดาห์ว่าง

หลังคลิกปุ่ม "What type of input?": แสดง "Type of input Expected: week"

หมายเหตุ: รูปภาพตัวอย่างจากต้นฉบับไม่ได้รวมอยู่ในเนื้อหานี้