HTML 5输入类型=“数字” Chrome上的浮点数元素 [英] HTML 5 input type="number" element for floating point numbers on Chrome

查看:172
本文介绍了HTML 5输入类型=“数字” Chrome上的浮点数元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < input type =我需要让用户输入浮点数,所以我使用下面的元素:号码name =my_numberplaceholder =输入号码/> 

在Firefox上效果很好,但Chrome会抱怨当我尝试输入数字时,数字不是整数小数。这对我的情况来说是个问题。如果我输入步骤属性,则Chrome允许使用浮点数:

 < input type =numbername =my_numberplaceholder =Enter numberstep =0.1/> 

但是接下来的问题是0.15无法输入... 步骤似乎不符合我的需要。 W3C规范属性中提到了浮点数字,输入类型=数字



如何让Chrome在不使用步骤的情况下接受浮点数属性?

解决方案

尝试< input type =numberstep =任何/>



它不会有验证问题,而且箭头的步骤为1


约束验证:当元素有一个允许值的步骤,
是应用算法将字符串转换为数字的结果
由元素值赋给的字符串是一个数字,从步骤基数中减去的
数字不是
整数倍数的允许值步骤,元素会遭遇步长不匹配。 p>

以下范围控制只接受0..1范围内的值,而
al低于该范围的256个步骤:

< input name = opacity type = range min = 0 max = 1 step = 0.00392156863>
$ b


跟随控制允许在任何时间选择任何时间,任何
准确度(例如千分之一秒准确度或更高):

< input name = favtime type = time step = any>
通常情况下,时间控制是
,限制为一分钟的精确度。


http://www.w3.org/TR/2012/WD-html5-20121025/common-input-element-attributes.html#attr-input-step


I need to have users enter floating point numbers, so I use the following element:

<input type="number" name="my_number" placeholder="Enter number"/>

Works great on Firefox, but Chrome complains that the number is not an integer when I try to enter a decimal. That's a problem for my case. If I enter a step attribute, then Chrome allows the floating point number:

<input type="number" name="my_number" placeholder="Enter number" step="0.1"/>

But then the problem is 0.15 can't be entered... The step doesn't appear to suit my needs. The W3C spec mentions floating-point numbers throughout the attributes of input type="number".

How do I get Chrome to accept floating point numbers without the step attribute?

解决方案

Try <input type="number" step="any" />

It won't have validation problems and the arrows will have step of "1"

Constraint validation: When the element has an allowed value step, and the result of applying the algorithm to convert a string to a number to the string given by the element's value is a number, and that number subtracted from the step base is not an integral multiple of the allowed value step, the element is suffering from a step mismatch.

The following range control only accepts values in the range 0..1, and allows 256 steps in that range:

<input name=opacity type=range min=0 max=1 step=0.00392156863>

The following control allows any time in the day to be selected, with any accuracy (e.g. thousandth-of-a-second accuracy or more):

<input name=favtime type=time step=any>

Normally, time controls are limited to an accuracy of one minute.

http://www.w3.org/TR/2012/WD-html5-20121025/common-input-element-attributes.html#attr-input-step

这篇关于HTML 5输入类型=“数字” Chrome上的浮点数元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆