当前位置: 移动技术网 > IT编程>开发语言>Jquery > 全选、取消全选、单选

全选、取消全选、单选

2018年01月12日  | 移动技术网IT编程  | 我要评论

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

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网