HTML DOM 輸入月份 stepUp() 方法


HTML DOM 輸入 month stepUp() 方法按指定值遞增(增加)輸入 month 欄位的值。

語法

以下是語法 −

object.stepUp(number)

此處,如果省略 number 引數,則將值增加 1。

示例

我們來看一個輸入 month stepUp() 方法示例 −

 線上演示

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM stepUp()/stepDown() Demo</title>
<style>

   body{
      text-align:center;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%)
      center/cover no-repeat;
      height:100vh;
      color:#fff;
   }

   p{
      font-size:1.5rem;
   }

   input{
      width:40%;
   }

   button{
      background-color:#db133a;
      color:#fff;
      padding:8px;
      border:none;
      width:120px;
      margin:1rem;
      border-radius:50px;
      outline:none;
      cursor:pointer;
   }

</style>
</head>
<body>
<h1>stepUp()/stepDown() Method Demo</h1>
<p>Hi! Select your month of birth</p>
<input type="month">
<br>
<button onclick="incValue()">StepUp Value</button>
<button onclick="decValue()">StepDown Value</button>
<script>
   function incValue() {
      document.querySelector("input").stepUp();
   }
   function decValue() {
      document.querySelector("input").stepDown();
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

單擊“遞增值”或“遞減值”按鈕可增加或減少輸入 month 欄位的值。


更新於: 30-7-2019

53 次瀏覽

啟動您的 職業

透過完成課程獲得認證

開始
廣告