Possible Duplicate:
How can I make the HTML5 number field display trailing zeroes?可能重复:如何使HTML5号字段显示尾随零?
I'm trying to input a money value like "1.00", but when I enter this value the 0s are removed and it becomes "1", but if I input 1.11, it remains 1.11.
我正在尝试输入像“1.00”这样的货币值,但是当我输入这个值时,0被删除并且变为“1”,但是如果我输入1.11,它仍然是1.11。
I'm using <input type="number">
. I've tried using patterns but the extra 0s are always deleted. Also this only happens on iPhone with type="number"
我正在使用。我尝试过使用模式但是额外的0都会被删除。这也只发生在类型=“数字”的iPhone上
Does anyone know how to get around this? Perhaps a way to use type="text", but have the phone open the numeric view?
有谁知道怎么解决这个问题?也许是一种使用type =“text”的方法,但让手机打开数字视图?
2 个解决方案
#1
4
Here's what I used for my mobile shopping calculator.
这是我用于移动购物计算器的内容。
<input type="number" name="price" step="0.01" min="0.01" max="99" />
#2
2
Here's a possible trick:
这是一个可能的技巧:
Using position:absolute
and visilibity:hidden
, position your number
input on top of a text
input. Then, using an onchange
event handler on the number input, put parseFloat(this.value).toFixed(2)
into the text input.
使用position:absolute和visilibity:hidden,将数字输入放在文本输入的顶部。然后,在数字输入上使用onchange事件处理程序,将parseFloat(this.value).toFixed(2)放入文本输入。
#1
4
Here's what I used for my mobile shopping calculator.
这是我用于移动购物计算器的内容。
<input type="number" name="price" step="0.01" min="0.01" max="99" />
#2
2
Here's a possible trick:
这是一个可能的技巧:
Using position:absolute
and visilibity:hidden
, position your number
input on top of a text
input. Then, using an onchange
event handler on the number input, put parseFloat(this.value).toFixed(2)
into the text input.
使用position:absolute和visilibity:hidden,将数字输入放在文本输入的顶部。然后,在数字输入上使用onchange事件处理程序,将parseFloat(this.value).toFixed(2)放入文本输入。