select标签的对于大家来说很熟悉了,下面我来讲讲AngularJS中 对select的属性设置,做出选择某个下拉选项后控制其他标签的隐藏;
<select style="height:31px; width:100px" id="rewardMethod"name="rewardMethod" class="status_select" ng-model="state"> <option value="0" ng-selected='rewardMethod == "0"'>自动发放</option> <option value="1" ng-selected='rewardMethod == "1"'>指定中奖人</option> <option value="2" ng-selected='rewardMethod == "2"'>不发放奖品</option> </select> <div class="form-group" ng-if="state != 2"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1">优惠券</label> <div class="col-sm-9"> <select style="height:31px; width:100px" id="reward" name="reward" class="status_select"> <option ng-repeat='item in couponList' ng-value="item.id" ng-selected="couponInfoid == item.couponName">{{item.couponName}} 总数:{{item.countLimit}} </option> </select> </div> </div> <div class="form-group" ng-if="state == 0"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"><span class="red">*</span>奖品发放数量</label> <div class="col-sm-9"> <input type="text" name="rewardProvideCount" id="rewardProvideCount" class="form-control" check-type="required"> </div> </div> </form> </div>
其中在select中设ng-model = “state”双向绑定数据,他的值会随你选择下拉项而改变,就是选中的option的value;在下面的div中设置ng-if="state == 1" 进行控制;
当页面进行修改操作的时候,需要把原来的值填入表单中,所以加了ng-selected='rewardMethod == "2"'
在controller。js中设置$scope.rewardMethod=2;这样加载页面就会选中第三项;效果如下:
如果选择不发奖:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。