果冻豆的WebView都不尽如人意使用HTML maxlength属性的文本框都不、尽如人意、果冻、文本框

2023-09-04 04:57:35 作者:携剑笑红尘

果冻豆似乎并不像HTML的最大长度进行文字输入属性。这无疑限制了输入字符数,但试图超越的性格所允许的数量输入的那一刻,在文本框中失败。现在,你将无法在输入任何其他文本框和你也不会能够删除已经输入的字符,在文本框中。

Jelly Bean doesn't seem to like the maxlength attribute of HTML for text input. It certainly restricts the number of input characters but the moment you attempt to type beyond the allowed number of character, the text box fails. Now you won't be able to type in any other text boxes and nor will you be able to delete the already input character, in that text box.

如果您还没有面临过这样的,然后自己尝试一下在一个简单的HTML和检查。请告诉我,如果你有任何线索来解决这一点。

If you haven't already faced this, then try it yourself on a simple HTML and check. Please tell me if you have any clue for solving this.

推荐答案

我也遇到过在我的应用程序相同的问题

I have also experienced the same problem in my app

现在我已经有JS处理它,它去除了所有的输入文本和textarea的最大长度的属性,并从输入查询超过所需的文本停止用户。这里,假定所有的输入文本和文本区域具有唯一id

for now I have handled it with js, which removes all maxlength attributes from input text and textarea and stops user from inputing more than the required text. Here it is assumed that all input text and textarea have unique id.

code也可在的jsfiddle

    $(document).ready(function () {

        var ver = window.navigator.appVersion;
            ver = ver.toLowerCase();

        if ( ver.indexOf("android 4.1") >= 0 ){            

            var idMaxLengthMap = {};

            //loop through all input-text and textarea element
            $.each($(':text, textarea, :password'), function () {
                var id = $(this).attr('id'),
                    maxlength = $(this).attr('maxlength');

                //element should have id and maxlength attribute
                if ((typeof id !== 'undefined') && (typeof maxlength !== 'undefined')) {
                    idMaxLengthMap[id] = maxlength;

                    //remove maxlength attribute from element
                    $(this).removeAttr('maxlength');

                    //replace maxlength attribute with onkeypress event
                    $(this).attr('onkeypress','if(this.value.length >= maxlength ) return false;');
                }
            });

            //bind onchange & onkeyup events
            //This events prevents user from pasting text with length more then maxlength
            $(':text, textarea, :password').bind('change keyup', function () {
                var id = $(this).attr('id'),
                    maxlength = '';
                if (typeof id !== 'undefined' && idMaxLengthMap.hasOwnProperty(id)) {
                    maxlength = idMaxLengthMap[id];
                    if ($(this).val().length > maxlength) {

                        //remove extra text which is more then maxlength
                        $(this).val($(this).val().slice(0, maxlength));
                    }
                }
            });
        }
    });​

有关此问题的错误已开业 35264

The bug for this issue was already opened at 35264