angularjs实现下拉列表的选中事件示例

风景旧曾谙,阳春三月归;烟云十年后,又见江南花。夜晚的这一刻,我独赏风景。有很多人觉得,一个人旅行好无聊。可我却偏偏喜欢一个人。

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;这样加载页面就会选中第三项;效果如下:

如果选择不发奖:

以上就是angularjs实现下拉列表的选中事件示例。人生最后悔的,莫过于年轻是没有好好学习。更多关于angularjs实现下拉列表的选中事件示例请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
AngularJS tab栏实现和mvc小案例实例详解

基于AngularJS拖拽插件ngDraggable.js实现拖拽排序功能

AngularJS实现的自定义过滤器简单示例

ionic使用angularjs表单验证(模板验证)

用WebStorm进行Angularjs 2开发(环境篇:Windows 10,Angular-cli方式)