你能告诉我如何限制用户不能在名称字段中输入十个字符吗?如果用户输入超过 10 个字符,他将无法输入。请提出更好的方法?
http://plnkr.co/edit/w1cidR23RYLAYE6dlvXd?p=preview 我有一个名称字段,用户只能在其中输入不超过十位数的名称。如果用户尝试输入更多内容,则不允许。
<td ng-if="value.type == 'FIELD' && isEditableMode && value.editable && value.dataType!='DATE'">
<div class="form-group" ng-class="{'has-error': myform[key].$invalid}">
<input type="text" name="{{key}}" class="form-control" ng-model="value.value">
</div>
</td>
最佳答案
您可以简单地设置 maxlength
属性。
The
maxlength
attribute specifies the maximum number of characters allowed in the input element.
演示:
<input maxlength="10" type="text"/>
关于javascript - 如何限制用户不能输入超过十个字符的名字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53264807/