HTML DOM 输入 DatetimeLocal 的 max 属性
htmlweb developmentfront end technology更新于 2025/9/18 11:24:17
HTML DOM 输入 DatetimeLocal 的 max 属性返回/设置输入 DatetimeLocal 的 max 属性。
语法
以下是语法 −
- 返回字符串值
inputDatetimeLocalObject.max
- 将 max 设置为字符串值
inputDatetimeLocalObject.max = YYYY-MM-DDThh:mm:ss
字符串值
此处,"YYYY-MM-DDThh:mm:ss"可以是以下减号;
| stringValue | Details |
|---|---|
| YYYY | 定义年份(例如:2006) |
| MM | 定义月份(例如:06 表示六月)。 |
| DD | 它定义了天数(例如:17) |
| T | 它是日期和时间的分隔符 |
| hh | 它定义了小时(例如:02) |
| mm | 它定义了分钟(例如:21) |
| ss | 它定义了秒(例如:40) |
示例
让我们看一个 Input 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>
输出
这将产生以下输出 −
点击"续保"按钮前 −

点击"续保"按钮后 −

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

