简体   繁体   English

在HTML中,在输入标签中使用'step'属性的目的是什么?

[英]In html what's the purpose of using 'step' attribute in input tag?

the purpose of using step attribute in input tag in html? 在html中使用输入标签中的step属性的目的?

input type="number" name="points" min="0" max="100" step="10" value="30"

From the above line minimum length is zero, maximum length is 100, default value is 30 but i can't understand what action doing when assign step="10" 从上面的行最小长度为零,最大长度为100,默认值为30但我无法理解当分配step =“10”时正在做什么动作

You can think of Step as how many steps you have to move from the current value. 您可以将Step视为从当前值移动的步数。

For example, 例如,

<input type="number" name="points" min="0" max="100" step="10" value="30" />

Imagine yourself in a staircase. 想象一下自己在楼梯里。 Here if you imagine value to be the stair number on which you are standing, step is the next x number of steps after which you can stop. 在这里,如果您想将value设置为您所站立的楼梯号,则step是您可以停止的下一个x步骤。

In your case you start with value="30" , means you are standing on stair number 30 and your step="10" means you can only stop at stair number 40 , 50 , 60 etc. 在你的情况你开始value="30" ,意味着你是站在楼梯30号和你的step="10"意味着你只能停在楼梯数量405060等。

If your value="31" means you are standing on stair number 31 and your step="10" means you can only stop at stair number 41 , 51 , 61 , etc. 如果value="31"意味着你是站在阶梯数31和您的step="10"意味着只能停在楼梯数415161等。

The step attribute specifies the legal number intervals for an element. step属性指定元素的合法数字间隔。 Example: in your case, step="10", legal numbers could be -10, 0, 10, 20, etc. Still if you can't get it, you can go through this link. 示例:在您的情况下,step =“10”,合法的数字可以是-10,0,10,20等。如果您无法获得它,您可以通过此链接。

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_step http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_step

The step attribute is used to state what steps between the min and max value are allowed. step属性用于说明允许的最小值和最大值之间的步骤。 In this case the values 0, 10, 20, ..., 100 are allowed, not for example 12 or 57. 在这种情况下,允许值0,10,20,...,100,而不是例如12或57。

Do note that support for this in browsers is quite patchy at the moment, so you can't rely on the value sent to the server to actually be only one of the allowed ones. 请注意,目前在浏览器中对此的支持非常不完整,因此您不能依赖发送到服务器的值实际上只是其中一个允许的值。

And there is no length defined in that element. 并且该元素中没有定义长度。 It is the minimum and maximum values that specified. 它是指定的最小值和最大值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM