文章标题 AngularJs购物车表格的制作
来源:互联网 发布:mac软件为什么无法删除 编辑:程序博客网 时间:2024/05/16 07:11
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script src="angular.js"></script> <script src="angular-route.js"></script> <style> .a{ width: 1400px; height: 500px; margin: 0 auto; margin-top: 120px} .b{width: 1400px; height: 50px;} .c{width: 1400px; height: 50px; } .d{float: right; width: 150px; height: 50px;background-color: red} .e{width: 1400px; height: 380px} .h{ margin-top: 100px} table{width: 1400px; height:400px} .num{ width: 70px; text-align: center; } .f{width: 150px; height: 50px; background-color: red} </style></head><body ng-app="myAPP" ng-controller="myCtrl"> <div class="a"> <div class="b"><h2>我的购物车</h2></div> <hr/> <div class="c"> <input class="f" ng-click="deleteSel()" type="button" value="批量删除"/> <button class="d" ng-click="removeAll()">清空购物车</button> </div> <div class="e"> <table ng-hide="getSize()" border="1" cellpadding="10" cellspacing="0"> <thead> <tr> <th><input type="checkbox" ng-model="selectAll" ng-click="selectAllFun()"/></th> <th>name</th> <th>price</th> <th>number</th> <th> totalPrice</th> <th>option</th> </tr> </thead> <tbody> <tr ng-repeat="x in users"> <th><input ng-model="x.state" type="checkbox"/></th> <td>{{x.myname}}</td> <td>{{x.myprice | currency:"¥"}}</td> <td><button style="background-color: #0c60ee" ng-click="reduce($index)">-</button> <input type="number" class="num" ng-model="x.mynumber" ng-change="change($index)" /> <button style="background-color: #0c60ee" ng-click="add($index)">+</button> </td> <td>{{x.myprice*x.mynumber | currency:"¥"}}</td> <td><button style="background-color: #0c60ee" ng-click="remove($index)">删除</button></td></tr> </tr> <tr> <td colspan="6"><span>总价:</span><span ng-bind="totalQuantity() | currency:'¥'"></span></td> </tr> </tbody> </table> <p class="h" ng-show="getSize()">您的购物车为空,请先逛<a href="#">购物车</a></p> </div> </div></body><script> var app=angular.module("myAPP",[]); app.controller("myCtrl",function ($scope) { $scope.users=[{ myname:"qq",myprice:"12.9",mynumber:2,mypriceone:"25.80"}, { myname:"wx",myprice:"23.90",mynumber:1,mypriceone:"23.90"}, { myname:"wx",myprice:"99.90",mynumber:1,mypriceone:"99.90"}]; //减少数量 $scope.reduce = function(index){ if( $scope.users[index].mynumber > 1){ $scope.users[index].mynumber--; }else{ $scope.remove(index); } } //添加数量函数 $scope.add = function(index){ $scope.users[index].mynumber++; } //所有商品总价函数 $scope.totalQuantity = function(){ var allprice = 0 for(var i = 0 ; i <$scope.users.length;i++ ){ allprice += $scope.users[i].mynumber * $scope.users[i].mypriceone; } return allprice; } //清空购物车 $scope.removeAll = function(){ if(confirm("你确定套清空购物车所有商品吗?")){ $scope.users = []; } } //删除当前商品 $scope.remove = function(index){ if(confirm("确定要清空数据吗")){ $scope.users.splice(index,1) } } //全选方法 $scope.selectAll = false; $scope.selectAllFun = function(){ if($scope.selectAll){ for(index in $scope.users){ $scope.users[index].state = true; } }else{ for(index in $scope.users){ $scope.users[index].state = false; } } } //批量删除 $scope.deleteSel=function(){ var userNames=[]; for(index in $scope.users){ if($scope.users[index].state == true){ userNames.push($scope.users[index].myname); } } if(userNames.length>0){ if(confirm("是否删除选中项?")){ for(i in userNames){ var myname=userNames[i]; for(i2 in $scope.users){ if($scope.users[i2].myname==myname){ $scope.users.splice(i2,1); } } } } }else{ alert("请选择删除的项") } } //判断数据源的长度 $scope.getSize = function(){ if($scope.users.length > 0 ){ return false; }else{ return true; } } });</script></html>
阅读全文
0 0
- 文章标题 AngularJs购物车表格的制作
- angularjs制作购物车功能
- 文章标题AngularJS学习
- AngularJS实现购物车功能,表格的删除,查询,排序功能
- 文章标题 表格的批量删除
- jquery制作闪烁的文章标题列表
- iText制作表格比较好的文章
- iText制作表格比较好的文章
- 文章标题 AngularJs 之 模态框
- 文章标题 AngularJs表单验证
- angularjs实现的购物车功能
- AngularJs实现简单的购物车
- angularjs之购物车的增改查1
- Angularjs实现简单的购物车
- AngularJs简单购物车的实现
- ionis 和angularjs 购物车的代码
- angularjs实现购物车的一些功能
- 【AngularJS】购物车实例
- highcharts数据标签显示在柱状图里面解决办法
- TreeMap排序规则
- MFC基础教程
- Linux学习:I/O 映射(ioremap)和writel/readl
- Android ViewPager之tab万能适配器
- 文章标题 AngularJs购物车表格的制作
- 史无前例企业架构分享--SSM组合+springmvc+mybatis+shiro+restful+bootstrap
- Synchronize,Lock和volatile的区别
- 验证数字的正则表达式集 验证数字:^[0-9]*$ 验证n位的数字:^\d{n}$ 验证至少n位数字:^\d{n,}$ 验证m-n位的数字:^\d{m,n}$ 验证零和非零开头的数字:^(0
- 欢迎使用CSDN-markdown编辑器
- 深度学习-根据日志画loss-acc折线图
- JAVA虚拟机体系结构
- 中级javaScript之Sum All Numbers in a Range
- 递归式求解-主方法