Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Android上PhoneGap应用程序的Webview文本字段中的Maxlength_Javascript_Android_Cordova_Maxlength - Fatal编程技术网

Javascript Android上PhoneGap应用程序的Webview文本字段中的Maxlength

Javascript Android上PhoneGap应用程序的Webview文本字段中的Maxlength,javascript,android,cordova,maxlength,Javascript,Android,Cordova,Maxlength,我试图在Android的PhoneGap中实现maxlength,但无法限制字符,因为它从未获取正确的字符代码。从下面代码中删除密钥的字符代码与任何其他密钥的字符代码相同 $(".limit-thirtyfive").bind("paste", function(e) { // access the clipboard using the api if (e.keyCode != 8 || e.keyCode != 46) { if ($(

我试图在Android的PhoneGap中实现maxlength,但无法限制字符,因为它从未获取正确的字符代码。从下面代码中删除密钥的字符代码与任何其他密钥的字符代码相同

$(".limit-thirtyfive").bind("paste", function(e) {
        // access the clipboard using the api
        if (e.keyCode != 8 || e.keyCode != 46) {
            if ($(this).val().length >= 33) {
                $(this).val($(this).val().substr(0, 33));
            }
        }
    });

$('.limit-ten').keyup(function(e) {
        if (e.keyCode != 8 || e.keyCode != 46) {
            if ($(this).val().length >= 10) {
                $(this).val($(this).val().substr(0, 10));
            }
        }
    });

一般长度限制

您只需使用所引用的输入元素的
maxlength
属性即可

<input type="text" maxlength="5"/>

在Nexus 9上无法正常工作。我还想限制一些特殊字符。我试过使用keyup。它还限制了退格&如果用户快速键入,regex将无法正常工作。我在问题中添加了keyup代码
$('your_input').onchange(function(){
    $(this).val($(this).val().replace(/a/g, ''));
});