移动浏览器中textarea的数字输入

时间:2013-11-25 14:38:49

标签: javascript android jquery html

我正在为移动设备编写Web界面。我想限制textarea中的输入:数字0-9,空格,输入。我想查看textarea的默认数字小键盘。但是对于textarea默认情况下会显示标准键盘。如果我使用虚拟键盘(简单按钮和javascript)标准键盘仍然显示。如何禁用textarea的标准键盘或设置默认数字键盘?

5 个答案:

答案 0 :(得分:2)

您可以在inputmode中使用全局属性textarea。这将在Android和iPhone中打开数字键盘。其他键盘版本也可用,例如tel(电话键盘),emailurl

<textarea inputmode="numeric">
</textarea>

有关更多信息,请参见the MDN docs on inputmode

答案 1 :(得分:-1)

setRawInputType(InputType.TYPE_CLASS_NUMBER);

答案 2 :(得分:-1)

您必须将输入类型设置为“数字”。数字类型用于应包含数值的输入字段。您还可以对接受的号码设置限制。

实施例: 定义数字字段(有限制): 数量(1到5之间):

<input type="number" name="quantity" min="1" max="5">

使用以下属性指定限制:

  • max - 指定允许的最大值
  • min - 指定允许的最小值
  • 步骤 - 指定合法的号码间隔
  • value - 指定默认值

答案 3 :(得分:-1)

<EditText
    android:id="@+id/launch_codes"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/enter_launch_codes"
    android:inputType="number"
    android:imeActionLabel="@string/launch" />

使用输入类型编号以查看默认数字小键盘

答案 4 :(得分:-2)

使用android:inputType选项。

在xml布局文件中,您可以像这样定义textarea:

<EditText
    android:id=yourID
    android:inputType="phone" >
</EditText>