angularjs 复选框




 $scope.isSelected = function(id){ 
                return 
 $scope.checkedr.indexOf(id)!=-1;
        };  
 $scope.selecteds=[];
 $scope.so=function($event,id,o){
        var checkbox = $event.target;
        var action = (checkbox.checked?'add':'remove');
        $scope.updateSelected(action,id,checkbox.name);
   }
   $scope.updateSelected = function(action,id,name){
         if(action == 'add' && $scope.selecteds.indexOf(id) == -1){
            $scope.selecteds.push(id);
         }else{
            // 删除时进行返回元素和指定元素不相等的元素
            $scope.selecteds=$scope.selecteds.filter(function(ele){
                 return ele != id;
            })
         }
         if(action == 'remove' && $scope.selecteds.indexOf(id)!=-1){
             var idx = $scope.selecteds.indexOf(id);
             $scope.selecteds.splice(idx,1);
         }
     }


你可能感兴趣的:(angularjs,复选框)