HTML:
1 <div class="form-group">
2 <label class="col-sm-2 control-label">商户名称</label>
3 <div class="col-sm-4">
4 <input type="text" class="form-control " id="merchantName" ng-model="merchant.name"
5 ng-init="123" value="{{name}}" placeholder="请输入商户名称"
6 ng-class="{'red-border':merchantNameState}"
7 ng-change="tipState(this,'merchantNameState')">
8 </div>
9 <div class="col-md-4 red-font" ng-show="merchantNameState">请输入商户名称</div>
10 </div>
JS:
1 $scope.tipState=function (x,stateName) {
2 if(x.value!==''){
3 $scope[stateName]=false;
4 }
5 };
- 传递变量参数
;
$scope[stateName]=false
- ng-change的使用
必须定义 ng-model
转载于:https://www.cnblogs.com/luanhewei/p/5802967.html