为什么 maxlength 没有效果?

Why does maxlength have no effect?

<input class="input {{fields[$index].class}}" 
  ng-disabled="field.disabled != ''"  
  ng-required="field.name == zipcode"
  ng-model="fields[$index].value"
  name="{{field.name}}"
  type="{{field.type}}"
  id="{{field.name}}"
  maxlength="6"
>
<label placeholder=" {{field.label}}">

</label>

属性 maxlength="6" 对我没有影响。

我想在文本框中输入不超过 6 个字符。但是,我可以继续输入数字,文本框会显示它们。

用户应该可以输入某个邮政编码,而这些邮政编码在我的国家总是 6 个字符并且只有数字。

文本框只接受数字,这行得通,但它一直接受任意数量的数字/字符。

这里出了什么问题?

谢谢!

编辑:有人 post 编辑了我的代码 运行 它,它按预期工作。

如果这个问题不关闭就好了,这样我们仍然可以找到原始版本的问题,然后 post 问题/解决方案。

编辑:这是我的更多代码:

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>Mein Profil</h5>
                </div>
                <div class="ibox-content">
                    <form>
                        <div ng-repeat="field in fields track by $index" class="form-group row">
                            <div class="col-sm-5">
                               
                                <!-- alert({{field.name}});
                                alert({{field.type}});
                                alert({{fields[$index].class}}); -->
                                <div class="col-sm-10">
                                    <input class="input {{fields[$index].class}}" 
                                    ng-disabled="field.disabled != ''"  
                                    ng-required="field.name == zipcode"
                                    ng-model="fields[$index].value"
                                    name="{{field.name}}"
                                    type="{{field.type}}"
                                    id="{{field.name}}"
                                    ng-maxlength="6"
                                  >
                                  <label placeholder=" {{field.label}}">
                                           
                                  </label>
                                </div>
                            </div>


                            <!-- <div class="col-sm-5">
                               
                                <div class="col-sm-10">
                                    <input class="input {{fields[$index].class}}" 
                                    ng-disabled="field.disabled != ''"  
                                    ng-required="field.name == zipcode"
                                    ng-model="fields[$index].value"
                                    name="{{field.name}}"
                                    type="{{field.type}}"
                                    id="{{field.name}}"
                                    ng-maxlength="6"
                                  >
                                  <label placeholder=" {{field.label}}">
                                           
                                        </label>
                                </div>
                            </div> -->

                            <!-- <div class="col-sm-5">
                               
                               
                                   
                                <div class="col-sm-10">
                                    <input ng-if="fields2[$index].label != 'PLZ'" ng-disabled="fields2[$index].disabled != ''" class="input {{fields[$index].class}}" required='' id="{{fields2[$index].name}}"
                                      
                                    name="{{fields2[$index].name}}" ng-model="fields2[$index].value" type="{{fields2[$index].type}}"
                                    maxlength="255">
                                    <input ng-if="fields2[$index].label == 'PLZ'" ng-disabled="fields2[$index].disabled != ''" class="input {{fields[$index].class}}" required='' id="{{fields2[$index].name}}"
                                        only-numbers
                                        name="{{fields2[$index].name}}" ng-model="fields2[$index].value" type="{{fields2[$index].type}}"
                                        maxlength="255">
                                        <label placeholder=" {{fields2[$index].label}}">
                                           
                                        </label>
                                </div>
                            </div> -->
                        </div>
                        <div  class="form-group row">
                            <div class="col-sm-5">

                                <div class="col-sm-10">
                                    <input  class="input" autocomplete="new-password"
                                        name="new_password" ng-model="new_password"  type="password" id="new_password"
                                        maxlength="255">
                                        <label placeholder=" Neues Passwort">
                                   
                                        </label>
                                </div>
                            </div>
                            <div class="col-sm-5">
                                <div class="col-sm-10">
                                    <input  class="input" autocomplete="new-password"
                                        name="confirm_password" ng-model="confirm_password"  type="password" id="confirm_password"
                                        maxlength="255">
                                        <label placeholder=" Neues Passwort bestätigen"></label>
                                   
                                        </label>
                                </div>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="col-sm-4 col-sm-offset-2">
                            <!-- <button ng-click="handleActionUpdateProfile()" name="submit" id="create-tan"
                                class="btn btn-primary btn-sm">

                                Profil aktualisieren
                            </button> -->
                            <md-button id="create-tan"  ng-click="handleActionUpdateProfile()" type="submit" class="md-raised md-primary register-btn m-0 px-4">
                                Profil aktualisieren
                            </md-button>
                        </div>
                    </form>


                </div>
            </div>
        </div>
    </div>
</div>

一定是有其他干扰。如果您查看您发布的独立片段,则输入的字符不能超过这 6 个字符。查看以下代码段。

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<input class="input {{fields[$index].class}}" 
  ng-disabled="field.disabled != ''"  
  ng-required="field.name == zipcode"
  ng-model="fields[$index].value"
  name="{{field.name}}"
  type="{{field.type}}"
  id="{{field.name}}"
  maxlength="6"
>
<label placeholder=" {{field.label}}">

</label>