HTML DOM Input Time readOnly 属性
htmlweb developmentfront end technology更新于 2025/8/4 11:56:17
HTML DOM Input Time readOnly 属性设置/返回是否可以修改输入时间。
语法
以下是语法 −
- 返回布尔值 - true/false
inputTimeObject.readOnly
- 将 readOnly 设置为 booleanValue
inputTimeObject.readOnly = booleanValue
布尔值
此处,“booleanValue” 可以是以下 −
| boolean值 | 详细信息 |
|---|---|
| true | 定义输入时间字段为只读。 |
| false | 定义输入时间字段为非只读,可修改。 |
示例
让我们看一个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>
输出
这将产生以下输出 −
点击"编辑时间"按钮前 −

点击"编辑时间"按钮后 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

