简体   繁体   English

文本字段的掩码数字输入,默认为iPad数字输入?

[英]Mask number input for text field and default to iPad number input?

Background 背景

  • I have a form with a field that users will enter. 我有一个带有用户将输入的字段的表单。
  • The input of the field is all numeric. 该字段的输入全为数字。
  • However, the result of the field will be masked to a text input 但是,该字段的结果将被屏蔽为文本输入
    • eg a user typing "9999999" will see "9999-999" 例如,用户输入“ 9999999”将看到“ 9999-999”
  • The field will ultimately be submitted as text. 该字段最终将以文本形式提交。

I think the solution is to: 我认为解决方案是:

  • Use a plugin such as jQuery Mask to do input masking 使用jQuery Mask之类的插件进行输入掩码
  • Use the input type of "number" so that the iPad's keypad will default to a number 使用“数字”的输入类型,以便iPad的键盘默认为数字

Problem 问题

  • If I use the "number" input type, the masking won't work because it inserts a dash in a field reserved only for numbers. 如果使用“数字”输入类型,则屏蔽将不起作用,因为它会在仅保留数字的字段中插入破折号。
  • If I use the masking with a text field, the iPad's keypad doesn't default to a number. 如果我在文本字段中使用遮罩,则iPad的键盘默认不是数字。

I used the code below: 我使用下面的代码:

$(document).ready(function() {
 var isiPad = navigator.userAgent.match(/iPad/i) != null;
 if (!isiPad){
  $("#id").mask("99999-999");
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM