我在我的输入控件中使用Glyphicon图标,一旦它发现一些错误。Glyphicon图标上有错误和正确的图像,但我想在点击错误的glyphicon时清除该输入控件。但我想清除输入控件上点击错误的glyphicon.下面是我的代码。
<div class="{{layout=='horizontal'? fieldClass || 'col-lg-9':''}} ">
<div style="position:relative" class="input-group">
<span class="input-group-addon"><b>PD</b></span>
<div class="icon-addo addon-md">
<input type="text" class="form-control {{textboxClass}}" name="textControl" id="textControl" ng-readonly="readonly" ng-required="required"
maxlength="10" placeholder="{{placeholder || layout=='inline' ? labelText : ''}}" data-ng-model="vm.value" ng-blur="vm.onBlur()" />
<i ng-show="vm.state==1" class="form-control-feedback fa fa-spinner fa-spin" style="width: auto; height:auto; font-size: 25px; top:5px; right:10px"></i>
<i onclick="clearControl(this,'textControl');" class="form-control-feedback" ng-class="{'glyphicon glyphicon-ok': vm.state==2, 'glyphicon glyphicon-remove': vm.state==3}" style="width: auto; height:auto; font-size: 20px; top:0; right:10px"></i>
</div>
</div>
<div ng-show="textForm['textControl'].$error.required && (submitted || !textForm['textControl'].$pristine)" class="help-block ng-hide">{{labelText}} is required</div>
</div></i>
请帮助我
不要使用内联 onclick
处理程序。你可以简单地用 ngClick
指令。
<i ng-click="vm.value = ''" class="form-control-feedback" ng-class="{'glyphicon glyphicon-ok': vm.state==2, 'glyphicon glyphicon-remove': vm.state==3}" style="width: auto; height:auto; font-size: 20px; top:0; right:10px"></i>
我也建议清除HTML,把样式移到CSS文件里,这样会让你的代码更全面。