HTML DOM 輸入 DatetimeLocal max 屬性


HTML DOM 輸入 DatetimeLocal max 屬性返回/設定輸入 DatetimeLocal 的 max 屬性。

語法

以下是語法 −

  • 返回字串值
inputDatetimeLocalObject.max
  • max 設定為字串值
inputDatetimeLocalObject.max = YYYY-MM-DDThh:mm:ss

字串值

此處,“YYYY-MM-DDThh:mm:ss” 可以是以下內容 −

字串值詳細資訊
YYYY定義年份(例如:2006)
MM定義月份(例如:06 表示 6 月)。
DD定義日期(例如:17)
T作為日期和時間的分割符
hh定義小時(例如:02)
mm定義分鐘(例如:21)
ss定義秒(例如:40)

示例

讓我們看一個 輸入 DatetimeLocal max 屬性的示例 −

 即時演示

<!DOCTYPE html>
<html>
<head>
<title>Input DatetimeLocal 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>Datetime-Local-max</legend>
<label for="datetimeLocalSelect">Insurance Expiration:
<input type="datetime-local" id="datetimeLocalSelect" value="2019-07-01T23:59:59" max="2019-08-01T23:59:59" disabled>
</label>
<input type="button" onclick="renewInsurance()" value="Renew Insurance">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputDatetimeLocal = document.getElementById("datetimeLocalSelect");
   function renewInsurance() {
      inputDatetimeLocal.max = '2029-07-01T23:59:59';
      inputDatetimeLocal.value = inputDatetimeLocal.max;
      divDisplay.textContent = 'Renewed Insurance: '+inputDatetimeLocal.value;
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

點選‘續保’按鈕前 −

點選‘續保’按鈕後 −

更新於: 2019-Jul-30

99 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.