用户登录
用户注册

分享至

全选、取消全选、单选

  • 作者: 可爱FFFF
  • 来源: 51数据库
  • 2021-08-19

<!--html-->

<table class="table1">
<thead>
<tr>
<th> <input id="flag" type="checkbox" ng-model="select_all" ng-change="selectAll()"> </th>
<th>合同编号</th>
<th>合同名称</th>
<th>分配公司</th>
<th>更新时间</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="list in lists">
<td> <input type="checkbox" ng-model="list.checked" ng-change="selectOne()"> </td>
<td>{{list.contractnum}}</td>
<td>{{list.template.name}}</td>
<td>{{list.office.name}}</td>
<td>{{list.updateDate}}</td>
</tr>
</tbody>
</table>

 

<!--js-->

 

$scope.checked = [];//用来存放选中项的id
$scope.select_all = “”;
$scope.list = {
checked: “”
}

//全选
$scope.selectAll = function() {
if($scope.select_all) {
$scope.checked = [];
angular.forEach($scope.lists, function(i) {
i.checked = true;
$scope.checked.push(i.id);
})
} else {
angular.forEach($scope.lists, function(i) {
i.checked = false;
$scope.checked = [];
})
}
};

//单选
$scope.selectOne = function() {
angular.forEach($scope.lists, function(i) {
var index = $scope.checked.indexOf(i.id);
if(i.checked && index === -1) {
$scope.checked.push(i.id);
} else if(!i.checked && index !== -1) {
$scope.checked.splice(index, 1);
};
})

if($scope.lists.length === $scope.checked.length) {
$scope.select_all = true;
} else {
$scope.select_all = false;
}
}

 

软件
前端设计
程序设计
Java相关