月考练习,增删查

<!DOCTYPE html>
<html>


<head>
<meta charset="UTF-8">
<title></title>
<script src="libs/angular.min.js"></script>
<script src="libs/jquery-1.11.0.min.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope, $http) {
$http.get("json/bb.json").then(function(res) {
$scope.bb = res.data;
})
$scope.chaxun = "";
$scope.paixu = "";

$scope.addGood = function(){
var goodi = {}
goodi.name=$scope.name;
goodi.price=$scope.price;
goodi.nums=$scope.nums;
goodi.product=$scope.product;
$scope.bb.push(goodi);
}
$scope.Alldelete = function(){
if($scope.checkAll){
$scope.bb = [];
}else{
var ches = $("input[type=checkbox]:checked");
for (var i = ches.length-1;i>=0;i--) {
$scope.bb.splice(ches[i],value,1);
}
}
}
$scope.deleteMore = function(gname){
for (var i = 0; i < $scope.bb.length; i++) {
$scope.bb.splice(i,1);
break;
}
}
});
</script>
<style>
.red{
background-color: aqua;
}
.yellow{
background-color: antiquewhite;
}
</style>
</head>


<body ng-app="myApp" ng-controller="myCtrl">
<center>
<div>
查询:<input type="text" placeholder="请输入要查询的关键字" ng-model="chaxun" /> 排序:
<select ng-model="paixu">
<option value="name">姓名正序</option>
<option value="-name">姓名倒序</option>
<option value="price">价钱正序</option>
<option value="-price">价钱倒序</option>
</select><br />
<input type="button" value="入库/增加" ng-click="showAdd=!showAdd" />
</div>
<div ng-show="showAdd">
名称:<input type="text" ng-model="name"/><br /> 价钱:
<input type="text" ng-model="price" /><br /> 数量:
<input type="text" ng-model="nums" /><br /> 产地:
<input type="text" ng-model="product" /><br />
<input type="button" value="添加" ng-click="addGood();" />
</div>
<input type="button" value="批量删除" ng-click="Alldelete();"/>
<table border="1">
<tr style="background-color: #DCDCDC;">
<td><input type="checkbox" ng-model="checkAll" /></td>
<td>商品名称</td>
<td>价钱</td>
<td>数量</td>
<td>产地</td>
<td>操作</td>
</tr>
<tr ng-repeat="g in bb | filter:chaxun | orderBy:paixu" class="{{$index%2? 'yellow':'red'}}">
<td><input type="checkbox" ng-model="checkAll" /></td>
<td>{{g.name}}</td>
<td>{{g.price}}</td>
<td>{{g.nums}}</td>
<td>{{g.product}}</td>
<td>
<input type="button" value="删除" ng-click="deleteMore(gname);" />
</td>
</tr>
</table>
</center>
</body>


</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值