HTML DOM Input Time 步進屬性


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”按鈕 −

更新於: 30-7-2019

151 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.