输入最大长度在Android-Ionic上不起作用 [英] Input maxlength does not work on Android -Ionic

查看:117
本文介绍了输入最大长度在Android-Ionic上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < p>我有一个输入字段,并且我需要停止输入超过允许字符的用户。 input type =textname =callsignmaxlength =7> 

它在browser.But中工作,但不适用于Android设备?

解决方案

感谢您的所有答案。您的回答并不是我给出的正确解决方案。然后我为此创建了一个指令。



directive.js

  myApp.directive('limitChar' ,function(){
'使用严格';
返回{
restrict:'A',
范围:{
limit:'= limit',
ngModel:'= ngModel'
},
link:function(scope){$ b $ scope。$ watch('ngModel',function(newValue,oldValue){
if (newValue){
var length = newValue.toString()。length;
if(length> scope.limit){
scope.ngModel = oldValue;
}
}
});
}
};
})

html

 < input type =textlimit-char limit =7> 


I have an input field and also i need to stop the user from typing more than the allowed character.

<input type="text" name="callsign" maxlength="7" >

It is working in browser.But not working on android devices?

解决方案

Thanks for all your answers.Your answers didn't me a give a proper solution.Then i have created a directive for that.

directive.js

myApp.directive('limitChar', function() {
    'use strict';
    return {
        restrict: 'A',
        scope: {
            limit: '=limit',
            ngModel: '=ngModel'
        },
        link: function(scope) {
            scope.$watch('ngModel', function(newValue, oldValue) {
                if (newValue) {
                    var length = newValue.toString().length;
                    if (length > scope.limit) {
                        scope.ngModel = oldValue;
                    }
                }
            });
        }
    };
})

html

<input type="text" limit-char limit="7" >

这篇关于输入最大长度在Android-Ionic上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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