<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>周考三</title>
<script src="angular1.4.6.min.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myctrl", function ($scope) {
$scope.goods = [
{"id": 124, "name": "iphone", "price":"¥:5400", "num": 55,},
{"id": 154, "name": "ipad", "price": "¥:2300", "num": 25,},
{"id": 125, "name": "ionic", "price": "¥:9400", "num": 85,},
{"id": 185, "name": "Andriod", "price":" ¥:3800", "num": 10,},
];
$scope.bold = "bold";
$scope.title = 'name';
$scope.desc = 0;
$scope.key = '';
//删除
$scope.deletes =function(name){
var p;
for( index in $scope.goods){
p = $scope.goods[index];
if( p.name == name){
$scope.goods.splice(index,1);
alert("是否删除"+name+"商品");
}
}
};
$scope.delall =function(){
alert("删除全部");
$scope.goods.splice($scope.goods);
};
//根据标题title排序
$scope.togg =function(tit){
$scope.title = tit;
$scope.desc = !$scope.desc;
};
});
</script>
</head>
<body ng-app="myApp" ng-controller="myctrl">
<center>
<table cellpadding="10" cellspacing="0" border="1">
<tr>
<th><input type="text" ng-model="key" placeholder="请输入关键字"></th>
<th colspan="5" align="right" ng-click="delall()"><button style="background-color: red">批量删除</button></th>
</tr>
<tr>
<th><input type="checkbox"> </th>
<th ng-click="goods("id=")">商品编号</th>
<th ng-click="goods("name=")">商品名称</th>
<th ng-click="goods("price=")">商品价格</th>
<th ng-click="goods("num=")">商品库存</th>
<th>数据操作</th>
</tr>
<tr ng-repeat="x in goods | filter: {name: key} | orderBy: title : desc">
<th><input type="checkbox"> </th>
<td>{{x.id}}</td>
<td>{{x.name}}</td>
<td>{{x.price}}</td>
<td>{{x.num}}</td>
<td>
<button ng-click="deletes(x.name)") style="background-color: goldenrod">删除</button>
</td>
</tr>
</table>
</center>
</body>
</html>
JS-购物车
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 023|决策时间:用户思考了很久,又把商品放回去了,怎么办? 什么是“决策时间”?消费者的注意力时长越来越短,人们...