angularJS中ng-ng-repeat里的单选框(radio)和多选框(checkbox)赋值取值

本文介绍如何在AngularJS应用中使用ng-repeat处理多选(checkbox)和单选(radio)框的选择状态,包括实现全选/取消全选的功能及获取已选择项的值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

angularJS中ng-ng-repeat里的单选框(radio)和多选框(checkbox)赋值取值

HLML代码  多选
  <div class="hy-checkk hlyw-fg-pandect-l">
                  <input type="checkbox"   ng-model="x.checked"  ng-change="selectOne()"/>
                    <label class="abs-cell"></label>
                </div>
js代码   全选和取消
    $scope.cancelAllT = function () {
        angular.forEach($scope.dataDYWSB, function (i) {
            i.checked = true;

        });
    };
    $scope.cancelAllF = function () {
        angular.forEach($scope.dataDYWSB, function (i) {
            i.checked = false;
        });
    };
多选框取值
 sum=true;
          $scope.dataHT='';
          angular.forEach($scope.dataDYWSB, function (i) {
              if(i.checked){

                  if(sum){
                      $scope.dataHT= $scope.dataHT+'{"xsDvId":'+ i.xsDvId+'}';
                      sum=false;
                  }else {
                      $scope.dataHT= $scope.dataHT+',{"xsDvId":'+ i.xsDvId+'}';
                  }
              }
          });
 HTML代码   单选 
   <div   ng-repeat="x in dataDYWSB">

 <div class="hlyw-dx-main">
                         <div class="hlyw-dx-main-l">是否检修</div>
                         <div class="hlyw-dx-main-c"> <input type="radio" class="hy-radio" ng-model="x.jxFlag" value="Y"> 是</div>
                         <div class="hlyw-dx-main-c"> <input type="radio" class="hy-radio" ng-model="x.jxFlag" value="N" > 否</div>
                     </div>
                     <div class="hlxnyyw-po-split-ss"></div>
                     <div class="hlyw-dx-main">
                         <div class="hlyw-dx-main-l">是否到位</div>
                         <div class="hlyw-dx-main-c"> <input type="radio" class="hy-radio" ng-model="x.dwFlag" value="Y"> 是</div>
                         <div class="hlyw-dx-main-c"> <input type="radio" class="hy-radio"   ng-model="x.dwFlag"  value="N" > 否</div>
                     </div>
                     <div class="hlxnyyw-po-split-ss"></div>
                     <div class="hlyw-dx-main">
                         <div class="hlyw-dx-main-l">是否完成</div>
                         <div class="hlyw-dx-main-c"> <input type="radio" class="hy-radio"  ng-model="x.doneFlag" value="Y"  > 是</div>
                  
</div>

取值
 console.log($scope.dataDYWSB);
            console.log(JSON.stringify($scope.dataDYWSB));







 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值