怎样才能把“0”去掉呢?来自 的占位符在移动 Safari 中?
我有一个供用户输入货币金额的输入字段:
<input type="number" value="{{ order.amount }}" />
我选择了数字输入类型,因为我希望在单击该字段时显示数字键盘。我无法使用 type="text" pattern="[0-9]*"
(建议 此处),因为这会导致出现没有小数点的纯数字输入板。
不幸的是,如果 value
属性不是数字(包括空字符串或空格),则该字段将以默认值“0”呈现:
这很糟糕,因为用户需要点击输入值之前⌫。
有什么办法可以解决这个问题吗?
更新:我是个白痴。一些 JavaScript 正在验证并重新格式化该字段。没关系。
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. 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.
Unfortunately, if the value
attribute is anything but numeric (including an empty string or space), the field renders with a default value of "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. Nevermind.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会查看您用于设置此字段的
value
属性的代码 (value="{{ order.amount }}"
)。我这样说的原因是,在 Mobile Safari 中,“普通”数字字段为空,即默认情况下没有0
。您的屏幕截图表明您正在使用 jQuery Mobile,因此我使用它进行了检查,以防问题所在,但同样,没有默认值为零。
就其价值而言,这是我正在使用的标记(它在 iOS 模拟器和 iPhone 3GS 上呈现空数字字段):
I would look at the code you are using to set the
value
attribute of this field (value="{{ order.amount }}"
). The reason I say this is that in Mobile Safari a "vanilla" numeric field is empty, i.e. no0
by default.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.
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):