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

คุณสมบัติ HTML DOM Input Week max

คุณสมบัติ max ของ HTML DOM Input Week ใช้สำหรับดึงหรือกำหนดสัปดาห์สูงสุดที่อนุญาตให้กรอกในช่องป้อนสัปดาห์

ไวยากรณ์ (Syntax)

การดึงค่า max

inputWeekObject.max

การกำหนดค่า max

inputWeekObject.max = "YYYY-Www"

รูปแบบค่าสตริง (String Values)

ส่วนรายละเอียด
YYYYปี (เช่น 2017)
Wตัวคั่นระหว่างปีและสัปดาห์
wwสัปดาห์ (เช่น 52)

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

ตัวอย่างต่ออายุประกัน - อัปเดต max week

<!DOCTYPE html>
<html>
<head>
<title>Input Week max</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-max</legend>
    <label for="WeekSelect">สัปดาห์ปัจจุบัน: <input type="week" id="WeekSelect" value="2020-W01" max="2019-W52" disabled> </label> 
    <input type="button" onclick="renewInsurance()" value="Renew Insurance"> 
    <div id="divDisplay"></div> 
  </fieldset> 
</form> 
<script> 
  var divDisplay = document.getElementById("divDisplay"); 
  var inputWeek = document.getElementById("WeekSelect"); 
  divDisplay.textContent = 'Insurance Expired as of: Week' + inputWeek.max.split("-W")[1]; 
  divDisplay.textContent += ' ,' + inputWeek.max.split("-W")[0]; 
  function renewInsurance() { 
    inputWeek.max = '2029-W52'; 
    divDisplay.textContent = 'Insurance Renewed till: Week' + inputWeek.max.split("-W")[1]; 
    divDisplay.textContent += ' ,' + inputWeek.max.split("-W")[0]; 
  } 
</script> 
</body>
</html>

ผลลัพธ์

เริ่มต้น - แสดง "Insurance Expired as of: Week 52 ,2019" (ช่อง disabled)

คลิก "Renew Insurance" - max เปลี่ยนเป็น 2029-W52 แสดง "Insurance Renewed till: Week 52 ,2029"

การใช้งานร่วมกับ min: กำหนด min และ max พร้อมกันเพื่อจำกัดช่วงสัปดาห์ที่เลือกได้