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>輸出
它將生成以下輸出 -
點選 “編輯時間” 按鈕之前 -

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

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP