当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML Input Week step用法及代码示例


DOM Input Week step属性用于设置或返回Week字段的step属性的值。 HTML中的step属性用于设置元素的离散步长。周输入的默认步进值是1。step属性可以与min和max属性一起使用以创建合法值。

用法:

  • 它返回step属性。
    weekObject.step
  • 用于设置step属性。
    weekObject.step = number

属性值:它包含一个值,即数字,用于指定周字段的法定周间隔。它的默认值为1。


返回值:它返回一个数字值,代表法律字段在星期几的时间间隔。

示例1:本示例说明了如何返回属性。

<!DOCTYPE html> 
<html> 
  
<body style="text-align:center;"> 
  
    <h1 style="color:green;">  
            GeeksForGeeks  
        </h1> 
  
    <h2> 
      DOM Input Week step Property 
  </h2> 
  
    <input type="week" 
           id="week_id" 
           step="3"
           placeholder="Every 3rd week"> 
    <br> 
    <br> 
    <button onclick="myFunction()"> 
        Click Here! 
    </button> 
  
    <p id="gfg" 
       style="font-size:23px; 
              color:green;"> 
  </p> 
  
    <script> 
        function myFunction() { 
  
            // Accessing input value  
            var x = 
                document.getElementById( 
                  "week_id").step; 
            
            document.getElementById( 
              "gfg").innerHTML = x; 
        } 
    </script> 
  
</body> 
  
</html>

输出:(从第1周开始的每个第3周都只能选择)
在点击按钮之前:

单击按钮后:

示例2:本示例说明了如何设置属性。

<!DOCTYPE html> 
<html> 
  
<body style="text-align:center;"> 
  
    <h1 style="color:green;">  
            GeeksForGeeks  
        </h1> 
  
    <h2> 
      DOM Input Week step Property 
  </h2> 
  
    <input type="week" 
           id="week_id"
           step="5"
           placeholder="multiples of 5"> 
    <br> 
    <br> 
    <button onclick="myFunction()"> 
        Click Here! 
    </button> 
  
    <p id="gfg" 
       style="font-size:23px; 
              color:green;"> 
    </p> 
  
    <script> 
        function myFunction() { 
  
            // set step value  
            var x = 
                document.getElementById( 
                    "week_id").step = "3"; 
  
            document.getElementById( 
                    "gfg").innerHTML = 
                "The value of the step " + 
                "attribute was changed to " + x; 
        } 
    </script> 
  
</body> 
  
</html>

输出:
在点击按钮之前:

单击按钮后:

支持的浏览器:下面列出了DOM Input week step属性支持的浏览器:

  • 谷歌浏览器
  • Internet Explorer 10.0以上
  • Firefox
  • Opera
  • Safari


相关用法


注:本文由纯净天空筛选整理自ManasChhabra2大神的英文原创作品 HTML | DOM Input Week step Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。