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