【发布时间】: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