简体   繁体   中英

Html5 number input step and precision

I can't find out how to define a step value and a precision to a input[number]

1.01 is considered as invalid until I specify a step of 0.01 . But In that case I can't specify a specific step.

Same issue with big number. If I specify a step of 1000 and the user type 1001 the value is considered invalid ...

You can have a look to this example

I guess you want to disable step validation. If so, step="any" should work.

You probably just need to define a correct step and an initial value that suits your purpose.

The role of the value attribute is not fully explained in the step attribute documentation http://www.w3schools.com/tags/att_input_step.asp .

In the first input in your example, attributes are set to value = 1.01 and step = 1 (default value). The input will accept the following values: 1.01 + 1n . where n is an integer value. Example of accepted values are: 1.01, 2.01, 3.01 and so on, as well as -0.99, -1.99 -1.99 and so on.

As a general rule, the accepted values will be:

值 + 步长 * n

Wheren \\in \\mathbb{Z}.

You can have an idea of the accepted values by using the UP/DOWN arrow keys when the input is focused.

As suggested in previous answers, step="any" will disable the step validation, it won't disable the stepper functionality ( step will defaults to 1), but will require to implement the step validation by hand.

Take a look at the Definition and Usage of the step attribute:

The step attribute specifies the legal number intervals for an element.

Once it is out of the intervals, the number is illegal.

Try using Javascript code to take care of your need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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