[英]How can I remove the “0” placeholder from <input type=“number”> in Mobile Safari?
I have an input field for users to input a monetary amount:我有一个输入字段供用户输入货币金额:
<input type="number" value="{{ order.amount }}" />
I chose the number
input type because I want the number keyboard to appear when the field is clicked.我选择number
输入类型是因为我希望在单击该字段时出现数字键盘。 I can't use type="text" pattern="[0-9]*"
(suggested here ) because that causes the number-only input pad to appear which doesn't have a decimal point.我不能使用type="text" pattern="[0-9]*"
( 这里建议),因为这会导致出现没有小数点的纯数字输入板。
Unfortunately, if the value
attribute is anything but numeric (including an empty string or space), the field renders with a default value of "0":不幸的是,如果value
属性不是数字(包括空字符串或空格),则该字段将使用默认值“0”呈现:
This stinks because the user needs to hit ⌫ before entering a value.这很臭,因为用户需要在输入值之前点击⌫ 。
Is there any way to fix this?有没有什么办法解决这一问题?
Update: I'm an idiot.更新:我是个白痴。 Some JavaScript was validating and reformatting the field.一些 JavaScript 正在验证和重新格式化该字段。 Nevermind.没关系。
I would look at the code you are using to set the value
attribute of this field ( value="{{ order.amount }}"
).我会查看您用于设置该字段的value
属性的代码( value="{{ order.amount }}"
)。 The reason I say this is that in Mobile Safari a "vanilla" numeric field is empty, ie no 0
by default.我这么说的原因是,在 Mobile Safari 中,“vanilla”数字字段是空的,即默认情况下没有0
。
Your screenshot suggests to me that you're using jQuery Mobile, so I checked using that in case the issue lay there, but again, no default value of zero.您的屏幕截图向我表明您正在使用 jQuery Mobile,因此我使用它进行了检查,以防问题出现,但同样,没有默认值为零。
For what it's worth, this is the mark-up I'm using (which renders an empty number field in iOS emulators and on an iPhone 3GS):对于它的价值,这是我正在使用的标记(它在 iOS 模拟器和 iPhone 3GS 上呈现一个空的数字字段):
<input type="number" value="" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.