HTML DOM Input DatetimeLocal step 属性
htmlweb developmentfront end technology更新于 2025/6/22 16:44:17
HTML DOM Input DatetimeLocal step 属性确定秒或毫秒的合法间隔。
语法
以下是语法 −
- 返回数字值
inputDatetimeLocalObject.step
- 将 step 属性设置为数字值
inputDatetimeLocalObject.step = number
参数
参数 number 值 −
| 值 | 描述 |
|---|---|
| seconds | 有效值由能够完美整除 60 的数字组成(例如:10,15,20) |
| milliseconds | 有效值以"."开头,并且能够完美整除 1000(例如:.10, .20, .01) |
示例
让我们看一个 Input DatetimeLocal step 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Input DatetimeLocal step</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-step</legend>
<label for="datetimeLocalSelect">Local Date Time :
<input type="datetime-local" id="datetimeLocalSelect" step="2">
</label>
<input type="button" onclick="changeStep('10')" value="Step Seconds to 10">
<input type="button" onclick="changeStep('.10')" value="Step milliseconds to .10">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputDatetimeLocal = document.getElementById("datetimeLocalSelect");
function changeStep(myStep) {
inputDatetimeLocal.step = myStep;
if(inputDatetimeLocal.step.indexOf('.') === -1)
divDisplay.textContent = 'Seconds step: '+inputDatetimeLocal.step;
else
divDisplay.textContent = 'Milli-seconds step: '+inputDatetimeLocal.step;
}
</script>
</body>
</html>
输出
这将产生以下输出 −
点击"将秒数步进至 10"按钮 −

点击"将毫秒步进至 0.10"按钮 −

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

