HTML DOM Input Time step 属性

htmlweb developmentfront end technology更新于 2025/8/5 13:32:17

HTML DOM Input Time step 属性仅确定秒的合法间隔。

语法

以下是语法 −

  • 返回数值
inputTimeObject.step
  • 将 step 属性 设置为数值
inputTimeObject.step = number

参数

参数数值 −

秒有效值由能够整除 60 的数字组成(例如: 10,15,20)

示例

让我们看一个Input Time step属性的示例 −

<!DOCTYPE html>
<html>
<head>
<title>Input Time 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>Time-step</legend>
<label for="TimeSelect">Time: </label>
<input type="time" id="TimeSelect" step="2">
<input type="button" onclick="changeStep(20)" value="Step to 20">
<input type="button" onclick="changeStep(30)" value="Step to 30">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputTime = document.getElementById("TimeSelect");
   divDisplay.textContent = 'The current step is: '+inputTime.step;
   function changeStep(myStep) {
      inputTime.step = myStep;
      divDisplay.textContent = 'The current step is: '+inputTime.step;
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"步进至 20"按钮 −

点击"步进至 30"按钮 −


相关文章


有用资源