码迷,mamicode.com
首页 > 其他好文 > 详细

获取checkbox返回值

时间:2016-08-23 16:31:41      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

<div class="checkbox">
     <label>
         <input type="checkbox" value="0" name="全选" ng-checked="isSelected(‘0‘)" ng-click="updateSelection($event,‘0‘)">全选
     </label>
     <label>
         <input type="checkbox" value="1" name="BANNER" ng-checked="isSelected(‘1‘)" ng-click="updateSelection($event,‘1‘)">BANNER
     </label>
     <label>
         <input type="checkbox" value="2" name="资料库" ng-checked="isSelected(‘2‘)" ng-click="updateSelection($event,‘2‘)">资料库
     </label>
     <label>
         <input type="checkbox" value="3" name="最新公告" ng-checked="isSelected(‘3‘)" ng-click="updateSelection($event,‘3‘)">最新公告
      </label>
</div>
     $scope.selected=[];
        var updateSelected=function(action,value){
            if(action=="add"&&$scope.selected.indexOf(value)==-1){
                $scope.selected.push(value);
            }
            if(action=="remove"&&$scope.selected.indexOf(value)!=-1){
                var idx=$scope.selected.indexOf(value);
                $scope.selected.splice(idx,1);
            }
        }
        $scope.isSelected=function(value){
            if(value=="0"){
                return $scope.selected.indexOf("1")>=0&&$scope.selected.indexOf("2")>=0&&$scope.selected.indexOf("3")>=0;
            }else{
                return $scope.selected.indexOf(value)>=0;
            }
        }
        $scope.updateSelection=function(event,value){
            var checkbox=event.target;
            var action=(checkbox.checked?"add":"remove");
            if(value=="0"){
                updateSelected(action,"1");
                updateSelected(action,"2");
                updateSelected(action,"3");
            }else{
                updateSelected(action,value,checkbox.name);
            }
        }

 

获取checkbox返回值

标签:

原文地址:http://www.cnblogs.com/YangqinCao/p/5799401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!