maxlength在cordova android app中的输入类型文本中不起作用

时间:2014-09-24 07:04:28

标签: javascript android html html5 cordova

我试图在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应用程序中运行时会出现上述问题。

感谢任何帮助。

提前致谢。

1 个答案:

答案 0 :(得分:5)

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

&#13;
&#13;
<input                                     
       autocomplete="off" 
       autocorrect="off" 
       autocapitalize="off" 
       spellcheck="false">
&#13;
&#13;
&#13;