angular实现商品加减
来源:互联网 发布:pdf阅读器有没有mac 编辑:程序博客网 时间:2024/05/22 04:51
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style> table{ border-collapse: collapse; } th,td{ padding: 10px; border: 1px solid #000; } </style> <script src="angular-1.5.5/angular.min.js"></script> <script> var myapp=angular.module("myapp",[]); myapp.controller("myCtrl",function ($scope) { $scope.data=[{ name:"qq", price:"12.90", numbar:"2", totalPrice:"25.80", },{ name:"wx", price:"23.90", numbar:"1", totalPrice:"23.90", },{ name:"wx", price:"12.9", numbar:"1", totalPrice:"99.90", } ]; $scope.delAll=function () { $scope.data.length=0; }; $scope.del=function(index){ console.log(index); if(confirm("是否删除")) { $scope.data.splice(index,1); } }; $scope.checkAll=false; $scope.check2=function(){ if($scope.checkAll==true){ for(var i=0;i<$scope.data.length;i++){ $scope.data[i].check=true; } }else{ for(var i=0;i<$scope.data.length;i++){ $scope.data[i].check=false; } } }; //反着全选 var n=0; $scope.count=function(index){ //console.log(index); if($scope.data[index].check==true){ n++; }else{ n-- } console.log(n); if(n==$scope.data.length){ $scope.checkAll=true; }else{ $scope.checkAll=false; } }; $scope.min=function(index){ $scope.data[index].numbar--; if($scope.data[index].numbar<0){ $scope.data[index].numbar=0; } }; $scope.add=function(index){ $scope.data[index].numbar++; }; $scope.count=function(){ var n=0; console.log(0); for(var i=0;i<$scope.data.length;i++){ n+=$scope.data[i].price*$scope.data[i].numbar; } return n; }; }); </script></head><body ng-app="myapp" ng-controller="myCtrl"><h1>我的购物车</h1><button ng-click="delAll()">删除全部</button><table> <thead> <tr> <th><input type="checkbox" ng-model="checkAll" ng-click="check2()"></th> <th>name</th> <th>price</th> <th>numbar</th> <th>totalPrice</th> <th>option</th> </tr> </thead> <tbody> <tr ng-repeat="item in data"> <td><input type="checkbox" ng-model="item.check" ng-click="count($index)"></td> <td>{{item.name}}</td> <td>{{item.price}}</td> <td><span ng-click="min($index)">-</span><input type="numbar" ng-model="item.numbar"><span ng-click="add($index)">+</span></td> <td>{{item.price*item.numbar}}</td> <td><button ng-click="del($index)">删除</button></td> </tr> <tr> <td colspan="6"><p>总价:<a>{{count()}}</a></p></td> </tr> </tbody></table></body></html>
阅读全文
0 0
- angular实现商品加减
- angular实现商品购物
- js实现商品加减及统计
- angular实现商品筛选功能(过滤器)
- angular实现商品查询验证等功能
- Android利用布局实现伪自定义商品数量加减控件
- jquery快速实现商品数量加减的方法
- vue商品数量加减
- angular.js框架简单实现加载无限加载商品
- angularJS商品添加数量加减
- 购物车加减商品后台
- angular商品删除
- Angular购物车的加减
- HTML angular购物车:加减按钮改变数量+全选+低于1时提示删除商品+计算所有商品总价+清空购物车+单独删除+输入内容小于1时,自动变为1+反选
- js商品列表运用了angular的
- JS实现日期加减
- JS实现文本框加减
- 实现大数字加减。
- 自制按键手机
- 封装okhttp
- 3.3
- 各大浏览器清除缓存的快捷键
- Swift协议合成
- angular实现商品加减
- PullToRefresh
- 创建抽象类AA
- Okhttp网络请求
- GeekBand笔记-《STL与泛型编程 》 第四周
- Unity_与线程的关联
- non-local Means(非局部均值)降噪算法及快速算法原理与实现
- Swift协议合成
- Okhttp工具类