HTML DOM 輸入日期時間區域性 step 屬性


HTML DOM 輸入日期時間區域性 step 屬性決定秒或毫秒的合法間隔。

語法

語法如下所示 −

  • 返回數值
inputDatetimeLocalObject.step
  • step 屬性設定為數值
inputDatetimeLocalObject.step = number

引數

引數 number 值 −

說明
有效值由能夠完美除以 60 的數字構成(例如:10、15、20)
毫秒有效值以“.”開頭,並能夠完美除以 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” 按鈕

單擊 “毫秒步長為 .10” 按鈕 −

更新日期: 2019 年 7 月 30 日

234 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.