Firefox不允许在input [type = number]中输入小数 [英] Firefox does not allow decimals in input[type=number]

查看:450
本文介绍了Firefox不允许在input [type = number]中输入小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firefox中遇到了一些奇怪的行为.我有一个简单的input [type = number]字段,当我尝试在其中输入一个十进制值(例如4.5)时,浏览器在我的输入周围放置了难看的红色边框.

I encountered some strange behavior in Firefox. I have a simple input[type=number] field and when I try to type a decimal value in it (e.g. 4.5), the browser puts an ugly red border around my input.

<input type="number" />

如何解决此问题并覆盖Firefox的这种愚蠢行为?

How can I fix this and override this stupid behavior of Firefox?

请参阅jsFiddle

推荐答案

如果设置了step="0.01",则边框消失.

If you set a step="0.01", then the border disappears.

数字类型具有一个步进值,该步进值控制哪些数字有效(以及最大和最小),默认为1.此值也被实现用于步进按钮(即,按逐步增加按).

The number type has a step value controlling which numbers are valid (along with max and min), which defaults to 1. This value is also used by implementations for the stepper buttons (i.e. pressing up increases by step).

只需将此值更改为适当的值即可.但是,这也意味着用户只能使用小箭头按您的值进行操作.

Simply change this value to whatever is appropriate. However, this also means the user can step only by your value with the little arrows.

来自此答案

这篇关于Firefox不允许在input [type = number]中输入小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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