angular js實現全選
阿新 • • 發佈:2019-01-05
<!Doctype html>
<head>
<title>擼起袖子加油幹</title>
<meta charset='utf-8'>
<script src="http://www.jq22.com/jquery/angular-1.4.6.js"></script>
<script src="__STATIC__/js/jquery-3.3.1.min.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script >
</head>
<body ng-app="myApp" ng-controller="Ctrl">
<table border="1" width="600" height="400">
<tr>
<td>姓名</td>
<td>密碼</td>
<td>頭像</td>
<td><input type="checkbox" ng-model="box" ng-click="selectAll()" >
</td>
</tr>
<tr ng-repeat="n in news">
<td>{{n.nickname}}</td>
<td>{{n.password}}}</td>
<td>{{n.phone}}</td>
<td><input type="checkbox" ng-model="n.ck" /></td>
</tr>
</table >
</body>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('Ctrl', function($scope, $http) {
$http({
method: 'POST',
url: "{:url('Index/ceshi')}",
dataType: 'JSON'
}).then(function successCallback(response) {
$scope.news=response.data;
}, function errorCallback(response) {
// 請求失敗執行程式碼
});
$scope.selectAll = function(){
//選中
if($scope.box){
for(var i=0;i<$scope.news.length;i++){
//確認狀態為選中
$scope.news[i].ck = true;
}
}else{
for(var i=0;i<$scope.news.length;i++){
//狀態沒選中
$scope.news[i].ck = false;
}
}
};
});
</script>
</html>