gpt4 book ai didi

Chrome 上用于 float 的 HTML 5 输入类型 ="number"元素

转载 作者:技术小花猫 更新时间:2023-10-29 11:36:04 24 4
gpt4 key购买 nike

我需要让用户输入 float ,所以我使用了以下元素:

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

在 Firefox 上运行良好,但当我尝试输入小数时,Chrome 会提示数字不是整数。这对我来说是个问题。如果我输入一个 step 属性,那么 Chrome 允许 float :

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

但问题是无法输入 0.15... step 似乎不符合我的需要。 W3C specinput type="number" 的整个属性中提到了 float 。

如何让 Chrome 在没有 step 属性的情况下接受 float ?

最佳答案

尝试 <input type="number" step="any" />

它不会有验证问题,箭头的步长为“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

关于Chrome 上用于 float 的 HTML 5 输入类型 ="number"元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22654678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com