html – 已翻译的输入类型编号

我正在建设移动设备.

我有一个包含输入类型编号的表单.每当我为此输入设置值时,设备语言设置为阿拉伯语,它将以阿拉伯数字显示.

如果我做这样的事情:

document.getElementById(‘input-id’).value = 444

在UI中,我们可以看到输入的值为444,相当于444的阿拉伯数字.

我在输入类型=“文本”中没有此问题,因为它显示字符串,因此它不会转换它们.

我知道我可以使用输入类型文本,但我想保持与我的应用程序的其余部分的一致性并使用输入类型编号

我在Chrome,Safari和Firefox中遇到过这个问题.

澄清:我不希望它将其翻译成阿拉伯数字.我该怎么做?

最佳答案
HTML规范的
section on the Number input type规定:

Note: This specification does not define what user interface user agents are to use; user agent vendors are encouraged to consider what would best serve their users’ needs. For example, a user agent in Persian or Arabic markets might support Persian and Arabic numeric input (converting it to the format required for submission as described above). Similarly, a user agent designed for Romans might display the value in Roman numerals rather than in decimal; or (more realistically) a user agent designed for the French market might display the value with apostrophes between thousands and commas before the decimals, and allow the user to enter a value in that manner, internally converting it to the submission format described above.

这意味着要由浏览器决定什么才能“最好地满足用户的需求”.我想,唯一可以覆盖它的方法是将页面的语言设置为444表示为444的语言(例如英语).为此,我们简单地说:

<body lang="en">

但是,再次,这完全取决于浏览器决定是否坚持这一点.

点赞