【问题标题】:maxlength not working in input type text in cordova android appmaxlength在cordova android应用程序中的输入类型文本中不起作用
【发布时间】:2014-09-24 07:04:27
【问题描述】:

我正在尝试在 android cordova 3.5.0 应用程序中实现一个输入字段,如下所示:

<input type="text" maxlength="7" class="form-control" placeholder=" "/>

但是 maxlength 根本不起作用。

我尝试了以下使用javascript的解决方法:

function checkTestPressure(txtBox){

    if(txtBox.value.length > 7){
    console.log(" txtBox = "+ txtBox.value.length);
    var str = txtBox.value;
    str = str.substr(0,7);
    txtBox.value = str;
    }
}

html如下:

<input type="text" maxlength="7" class="form-control" onkeyup="checkTestPressure(this);" onblur="trimWhiteSpacesForTextBox(this);"  id="testpressure" placeholder=" ">

这首先有效,但如果我在 7 位数字后继续敲击键盘上的键,则输入文本字段将变为空并在我继续按下键时开始重新填充。

这是不可接受的,我只想要前 7 个字符,无论我按键盘上的键多少次,都不应填充该字段。

上面的代码在桌面浏览器中运行良好,但是当我在cordova android 应用程序中运行时会出现上述问题。

感谢任何帮助。

提前致谢。

【问题讨论】:

  • [已解决] 此问题是由于android的预测文本功能造成的。关闭预测文本会提供所需的输出。
  • 你可以从this stackoverflow post得到一个提示。
  • 如何禁用它?我也面临同样的问题。

标签: javascript android html cordova


【解决方案1】:

有点晚了,但是你可以使用这个属性来完成禁用文本更正/修改。

<input                                     
       autocomplete="off" 
       autocorrect="off" 
       autocapitalize="off" 
       spellcheck="false">

【讨论】:

  • 可行,但有没有办法同时获得自动完成文本长度限制?
  • 哦,它不适合我,因为我时间紧迫,我或者将type=tel 设置为快速修复。
  • @njzk2 我认为仅使用 HTML 是不可能的,因为我不认为操作系统建议仅使用有限数量的字符的单词。
猜你喜欢
  • 1970-01-01
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
  • 2019-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-20
相关资源
最近更新 更多