如何设置 Ionic 1 输入类型的最大长度


最大

长度 HTML5 属性在移动设备上无法正常工作,用于文本输入字段。如果启用了数字小键盘,它可以工作,但在使用文本小键盘时不起作用。

法典:

<ion-content class="p-l-10 p-r-10 had-header form_page">
<form ng-submit="vm.addAdvance()">
  <div class="list">
    <label class="item item-input InputFormFull">
      <span class="input-label">{{'note_message' | translate}}</span>
       <input type="text" placeholder="{{'notes_message' | translate}}" 
        ng-model="vm.advance.description" id="field2" ng-change="vm.fillStarted()" size="5" maxlength="5" required>
    </label>
    <button class="button trans-but m-t-10" type="submit">{{'save_message' | translate}}</button>
  </div>
</form>

可能的重复:输入最大长度在 Android -Ionic 上不起作用

尝试创建自己的指令:

    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;
                    }
                }
            });
        }
    };
})

目录:

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

最新更新