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;這樣加載頁面就會選中第三項;效果如下:
如果選擇不發獎:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答