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

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

Thuộc tính max của đối tượng Input Week trong HTML DOM trả về hoặc thiết lập tuần/năm lớn nhất được phép chọn. Định dạng: YYYY-Www (năm-tuần chuẩn ISO 8601).

Cú pháp

Lấy giá trị max

inputWeekObject.max

Thiết lập max

inputWeekObject.max = "YYYY-Www"

Cấu trúc giá trị

Thành phầnMô tả
YYYYNăm (ví dụ: 2017)
WPhân tách năm và tuần (bắt buộc W in hoa)
wwTuần (01-52/53, ví dụ: 52)

Ví dụ minh họa

Ô week value=2020-W01, max=2019-W52, disabled. Bảo hiểm hết hạn tuần 2019-W52. Nhấn nút gia hạn đến 2029-W52:

<!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">Tuần hiện tại: <input type="week" id="WeekSelect" value="2020-W01" max="2019-W52" disabled> </label> 
    <input type="button" onclick="giaHanBaoHiem()" value="Gia hạn bảo hiểm"> 
    <div id="divDisplay"></div> 
  </fieldset> 
</form> 
<script> 
  var divDisplay = document.getElementById("divDisplay"); 
  var inputWeek = document.getElementById("WeekSelect"); 
  divDisplay.textContent = 'Bảo hiểm hết hạn: Tuần' + inputWeek.max.split("-W")[1]; 
  divDisplay.textContent += ' ,' + inputWeek.max.split("-W")[0]; 
  function giaHanBaoHiem() { 
    inputWeek.max = '2029-W52'; 
    divDisplay.textContent = 'Bảo hiểm gia hạn đến: Tuần' + inputWeek.max.split("-W")[1]; 
    divDisplay.textContent += ' ,' + inputWeek.max.split("-W")[0]; 
  } 
</script> 
</body> 
</html>

Kết quả

  • Ban đầu: ô week 2020-W01 (disabled), hiển thị "Bảo hiểm hết hạn: Tuần52 ,2019".
  • Nhấn Gia hạn bảo hiểm: max đổi thành 2029-W52, hiển thị "Bảo hiểm gia hạn đến: Tuần52 ,2029".

Lưu ý: Trình duyệt ngăn chọn tuần > max trên picker. Cần validate lại server-side vì user có thể bypass.