在HTML的输入maxlength属性不上的HTC One M7工作 [英] maxlength attribute of input in html does not work on HTC One M7

查看:124
本文介绍了在HTML的输入maxlength属性不上的HTC One M7工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到具有最大长度=2属性一个简单的输入字段。在code看起来像下面这样:

I got a simple input field which has a maxlength="2" attribute. The code looks like this below:

<input id="txtLoginName" maxlength="2">

它适用于大多数Android设备的罚款。然而,在的HTC One M7,这是行不通的。在这个装置,它只是让我,因为我想进入尽可能多的字符。

It works fine on most Android devices. However, on the HTC One M7, it does not work. On this device, it just allows me to enter as many characters as I want.

任何建议?我想这应该是一个设备特定问题为止。

Any suggestion? I think it should be a device specific issue so far.

在此先感谢。

推荐答案

我注意到一对夫妇的项目这一问题。我认为Android的某些版本有最大长度坏的支持。

I've noticed this issue on a couple of projects. I think certain versions of Android have bad support for maxlength.

我的解决方案是使用从如果Max一直打到正在输入的字符检查和prevents量了一个jQuery的keydown功能。

My solution was to use a jQuery keydown function that checks the amount of characters and prevents anymore from being entered if the max has been hit.

$('#inputWithMaxLength').keydown(function (e) {

    var inputLength = jQuery(this).val().length;

    if(inputLength >= 10) {
        e.preventDefault();
        return false;
    }
}

我敢肯定,使其搜索与最大长度的属性的任何输入和创建动态jQuery的备份,你可以改变这一点。我不知道这会是相当虽然放缓。

I'm sure you could change this so that it searched for any input with attributes of maxlength and created a jQuery backup on the fly. I'm not sure if that would be rather slow though.

这篇关于在HTML的输入maxlength属性不上的HTC One M7工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆