批量删除

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.js" ></script>
<script type="text/javascript" src="js/jquery-3.2.1.min.js" ></script>
<script>
var app = angular.module("myapp",[]);

app.controller("myCtrl",function($scope,$http){

$scope.shuju = "";

$http({
method:"get",
url:"http://gank.io/api/data/Android/10/1"

}).then(function success(response){

$scope.shuju = response.data;

},function error(response){

});


//删除
$scope.shanchu = function($index){

//alert(a);

for(var i=0 ;i<$scope.shuju.results.length ; i++){
if($scope.shuju.results[i]._id == $index){
$scope.shuju.results.splice(i,1);
}
}


}


$scope.addshow = false;

$scope.newid = "";
$scope.newsource = "";
$scope.newtype = "";
$scope.newused = "";


$scope.tian = function(){

$scope.addshow = !$scope.addshow;

}

//添加
$scope.addt = function(){


if($scope.newid != null && $scope.newid  != ""){

if($scope.newsource != null && $scope.newsource  != ""){

if($scope.newtype != null && $scope.newtype  != ""){

if($scope.newused != null && $scope.newused  != ""){


var goods = {

_id : $scope.newid,
source : $scope.newsource,
type : $scope.newtype,
createdAt : new Date,
used : $scope.newused

}

$scope.shuju.results.push(goods);
$scope.addshow = false;



}else{
alert("used为空");
}

}else{
alert("type为空");
}

}else{
alert("source为空");
}

}else{
alert("id为空");
}


}


//修改


$scope.upshow = false;

$scope.newid1 = "";
$scope.newsource1 = "";
$scope.newtype1 = "";
$scope.newused1 = "";

$scope.xg = 0 ;

$scope.xiugai = function($index){

$scope.xg = $index;

$scope.upshow = !$scope.upshow;

$scope.newid1 = $scope.shuju.results[$index]._id;
$scope.newsource1 = $scope.shuju.results[$index].source;
$scope.newtype1 = $scope.shuju.results[$index].type;
$scope.newused1 = $scope.shuju.results[$index].used;

}

$scope.upx = function(){

$scope.shuju.results[$scope.xg]._id = $scope.newid1;
$scope.shuju.results[$scope.xg].source = $scope.newsource1;
$scope.shuju.results[$scope.xg].type = $scope.newtype1;
$scope.shuju.results[$scope.xg].createdAt = new Date;
$scope.shuju.results[$scope.xg].used = $scope.newused1;

$scope.upshow = false;
}


$(document).ready(function(){
//全选
$("#btn2").click(function(){

var v = $("input[type='checkbox']");
//alert(v.length);
for(var i=0 ; i<v.length ; i++){
if(v[i].checked == true){
for(var j = 0; j < v.length; j++) {
v[i].checked = !v[j].checked;
}
}else {
for(var z = 0; z < v.length; z++) {
v[i].checked = true;
}
}
}

});

//批量删除
$("#btn3").click(function() {
var checkboxarr = $("input[type='checkbox']:checked")
for(var z = 0; z < checkboxarr.length; z++) {

checkboxarr[z].parentNode.parentNode.remove();


}
})

});


});


</script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<center>

<input type="text" placeholder="搜索" ng-model="sou" />

<input type="button" value="添加" ng-click="tian()" />

<input type="button" value="全选/反选" id="btn2"/>

<input type="button" value="批量删除" id="btn3" />

<select ng-model="pai">
<option value="">---请选择---</option>
<option value="createdAt">按时间升序</option>
<option value="-createdAt">按时间降序</option>
<option value="_id">按id升序</option>
<option value="-_id">按id降序</option>
</select>

<table width="900px" border="1">
<tr>
<th>
<input type="checkbox" ng-model="aa" />
</th>
<th>序号</th>
<th>source</th>
<th>type</th>
<th>createdAt</th>
<th>used</th> 
<th>操作</th>

</tr>
<tr ng-repeat="s in shuju.results | orderBy:pai | filter:sou">
<td align="center">
<input type="checkbox" ng-model="aa"  />
</td>
<td align="center">{{s._id}}</td>
<td align="center">{{s.source}}</td>
<td align="center">{{s.type}}</td>
<td align="center">{{s.createdAt | date:"yyyy-MM-dd hh:mm:ss"}}</td>
<td align="center">{{s.used}}</td>
<td align="center">
<input type="button" value="删除" ng-click="shanchu(s._id)" />
<input type="button" value="修改" ng-click="xiugai($index)" />

</td>
</tr>

</table>

<div ng-show="addshow">
<input type="text" placeholder="添加ID" ng-model="newid"/><br /><br />
<input type="text" placeholder="添加source" ng-model="newsource" /><br /><br />
<input type="text" placeholder="添加type" ng-model="newtype" /><br /><br />
<input type="text" placeholder="添加used" ng-model="newused" /><br /><br />
<input type="button" value="添加" ng-click="addt()" />
</div>

<div ng-show="upshow">
<input type="text" placeholder="修改ID" ng-model="newid1"/><br /><br />
<input type="text" placeholder="修改source" ng-model="newsource1" /><br /><br />
<input type="text" placeholder="修改type" ng-model="newtype1" /><br /><br />
<input type="text" placeholder="修改used" ng-model="newused1" /><br /><br />
<input type="button" value="添加" ng-click="upx()" />
</div>

</center>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值