angular JS 多选框 全选 反选

<html>


<head>

<meta charset="UTF-8">

               //导入angular包

<script src="js/angular-1.5.5/angular.js"></script>
<title></title>

<script>

//配置好angular

var app = angular.module("myApp", []);
app.controller("ctict", function($scope) {
//定义一个数组
$scope.users = [{
name: 1,
state: false
}, {
name: 2,
state: false
}, {
name: 3,
state: false
}];
//全选
$scope.stateall = false;
$scope.xuan = function() {
if($scope.stateall) {
for(index in $scope.users) {
$scope.users[index].state = true;
}
} else {
for(index in $scope.users) {
$scope.users[index].state = false;
}
}
};
//反选
$scope.checkSelectAll = function() {
var flag = false;
for(index in $scope.users) {
if($scope.users[index].state) {


} else {
flag = true;
}
}
//至少有一个没有被选中
if(flag) {
$scope.stateall = false;
} else {
$scope.stateall = true;
}
}
//删除
$scope.detle=function(){
var selectedShop = [ ];
for(index in $scope.users){
if($scope.users[index].state){
selectedShop.push($scope.users[index].name);
}
}
if(selectedShop.length>0){
for(i1 in selectedShop){
for(i2 in $scope.users){
if(selectedShop[i1] == $scope.users[i2].name){
$scope.users.splice(i2,1);
}
}
}
}else{
alert("请先选择")
}
};
});
</script>
</head>


<body ng-app="myApp" ng-controller="ctict">
<button ng-click="detle()">删除</button>

<hr />

//表格显示数组中的数据

<table border="1 " cellpadding="10" cellspacing="0">
<thead>
<tr>
<th><input type="checkbox" ng-model="stateall" ng-click="xuan()" /></th>
<th>id</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<th><input type="checkbox" ng-model="user.state" ng-click="checkSelectAll()" /></th>
<th>{{user.name}}</th>
</tr>
</tbody>
</table>
</body>


</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值