作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
textarea name="firstname" id="firstname"-6ren">
form name="form" novalidate autocomplete="off" role="form">
textarea name="firstname" id="firstname" required data-ng-model="name" maxlength="160" minlength="50"></textarea>
div ng-messages="form.firstname.$error" role="alert">
span ng-message="required">
Please enter Name
</span>
span ng-message="minlength">
{{ 50 - name.length}}
</span>
/div>
/form>
最佳答案
尝试这个
<textarea name="firstname" id="firstname" required ng-model="firstname" ng-maxlength="160" ng-minlength="50"></textarea>
<div ng-show="myForm.firstname.$dirty" role="alert">
<span ng-show="myForm.firstname.$error.required"> Please enter Name
</span>
<span ng-show="myForm.firstname.$error.minlength"> Please enter atleast 50 characters
</span>
<span ng-show="myForm.firstname.$error.maxlength"> Maximum allowed characters are 160
</span>
</div>
var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<form name="myForm" novalidate autocomplete="off" role="form">
<textarea name="firstname" id="firstname" required ng-model="firstname" ng-maxlength="160" ng-minlength="50"></textarea>
<div ng-show="myForm.firstname.$dirty" role="alert">
<span ng-show="myForm.firstname.$error.required"> Please enter Name
</span>
<span ng-show="myForm.firstname.$error.minlength"> Please enter atleast 50 characters
</span>
<span ng-show="myForm.firstname.$error.maxlength"> Maximum allowed characters are 160
</span>
</div>
</form>
</div>
<span ng-show="firstname.length < 50"> Please enter atleast {{50 - firstname.length}} characters
</span>
var app=angular.module("app",[]);
app.controller("ctrl",function($scope){
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<form name="myForm" novalidate autocomplete="off" role="form">
<textarea name="name" id="firstname" required ng-model="firstname" maxlength="160" minlength="50"></textarea>
<div ng-show="myForm.name.$dirty" role="alert">
<span ng-show="myForm.name.$error.required"> Please enter Name
</span>
<span ng-show="firstname.length < 50"> Please enter atleast {{50 - firstname.length}} characters
</span>
</div>
</form>
</div>
关于angularjs - 如何在最小长度验证angularjs中显示输入长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42801348/
我是一名优秀的程序员,十分优秀!