獲取checkbox返回值


<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);
            }
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM