javascript - HTML5 : additional chars in input with type ="number"

标签 javascript android ios html

在我们的应用中,我们有许多用于填写学校成绩的输入。到目前为止我们已经

<input type="text" name="mark">

由于我们尝试使用 HTML5 的新功能,因此我们将其更改为

<input type="number" name="mark">

因此,在手机/平板电脑上,我们的界面仅包含数字。事情就是这样。可以输入“5+”等输入等级(例如一些两个字母的快捷方式“ab”等)。它可由用户自定义。

是否有任何方法可以扩展输入以将数字和所有字符视为有效,并将 Android/iOS 键盘布局扩展到仅此?

编辑:

不要忘记我想知道是否可以在移动设备上扩展键盘布局。如果不可能,我将通过一些验证返回到文本。

最佳答案

我相信您可以将 pattern 属性用于您所描述的内容:

A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored. The regular expression language is the same as JavaScript's. The pattern is not surrounded by forward slashes.

https://developer.mozilla.org/en/docs/Web/HTML/Element/Input

例如<input type="text" name="HasAPattern" pattern="[0-9A-Z]{3}" title="Enter 3 characters">

将导致输入元素仅允许 3 个字符。

不幸的是,我认为自定义键是不允许的,因此您必须使用添加了带有上述属性的数字模式的文本类型。

非标准键盘布局/输入按钮必须使用自定义键盘。

关于javascript - HTML5 : additional chars in input with type ="number",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28693688/

相关文章:

javascript - 你如何在 Windows 上的 node.js 中运行外部程序?

javascript - vm.$set 和 Vue.set 有什么区别?

Android Studio build.gradle 无法识别 gradle.properties 中的变量

android - 我想在我的按钮上使用 Widget.Button.Transparent 样式

Java 获取嵌套的 JSON 对象/数组

ios - 如何获取通知以将我带到所需的 viewController?

iphone - Xcode 4.2 和 iOS SDK 4.0

javascript - 如何聚合对象属性?

javascript - 为什么浏览器执行内容类型为 json 的 &lt;script&gt; ?

UITableViewCell 和 heightForRowAtIndexPath 的 iOS 动态高度