怎样才能把“0”去掉呢?来自 的占位符在移动 Safari 中?

发布于 2024-11-19 22:21:14 字数 662 浏览 4 评论 0原文

我有一个供用户输入货币金额的输入字段:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2024-11-26 22:21:14

我会查看您用于设置此字段的 value 属性的代码 (value="{{ order.amount }}")。我这样说的原因是,在 Mobile Safari 中,“普通”数字字段为空,即默认情况下没有 0

您的屏幕截图表明您正在使用 jQuery Mobile,因此我使用它进行了检查,以防问题所在,但同样,没有默认值为零。

就其价值而言,这是我正在使用的标记(它在 iOS 模拟器和 iPhone 3GS 上呈现空数字字段):

<input type="number" value="" />

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. no 0 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):

<input type="number" value="" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文