HTML DOM Input Time readOnly屬性


HTML DOM Input Time readOnly 屬性會設定/返回 Input Time 是否可修改。

語法

以下為語法 -

  • 返回布林值 - true/false
inputTimeObject.readOnly
  • 設定  readOnly 為 booleanValue
inputTimeObject.readOnly = booleanValue

布林值

此處,“booleanValue”可以是以下值 -

booleanValue詳細資訊
true定義 input time 欄位為 readOnly。
false定義 input time 欄位不為 readOnly 且可修改。

示例

下面我們來看一個 Input Time readOnly 屬性的示例 -

即時演示

<!DOCTYPE html>
<html>
<head>
<title>Input Time readOnly</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>Time-readOnly</legend>
<label for="TimeSelect">Appointment with Supervisor:</label>
<input type="time" id="TimeSelect" value="12:45" readOnly>
<input type="button" onclick="changeMeeting()" value="Edit Time">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputTime = document.getElementById("TimeSelect");
   function changeMeeting() {
      if(inputTime.readOnly === true)
         divDisplay.textContent = 'The meeting time cannot be altered';
      else
         divDisplay.textContent = 'The meeting time fixed at: '+inputTime.value;
   }
</script>
</body>
</html>

輸出

它將生成以下輸出 -

點選 “編輯時間” 按鈕之前 -

點選 “編輯時間” 按鈕之後 -

更新於: 2019-07-30

71 次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.