转自CSDN:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车</title>
<script src="angularjs/angular.js"></script>
<style>
.box{
width: %;
border-bottom: 1px solid silver;
}
.box1{
width: %;
margin-top: 5px;
}
.box1 button{
width: 100px;
height: 40px;
background: crimson;
color: white;
text-align: center;
line-height: 40px;
float: right;
border: ;
border-radius: 13px;
}
table{
width: %;
}
tr td button{
background: blue;
color: white;
border: ;
} </style>
<script>
var my=angular.module("my",[]);
my.controller("mys",function ($scope) {
/*声明数据对象,初始化商品信息,数据自拟且不低于四条*/
$scope.arr=[
{name:"qq",price:12.9,number:,state:false},
{name:"wx",price:23.9,number:,state:false},
{name:"aa",price:99.9,number:,state:false},
{name:"bb",price:10.9,number:,state:false}
];
/*删除条目*/
$scope.del=function (index) {
if(confirm("确定移除此项嘛?")){
$scope.arr.splice(index,);
}
}
/*点击”+”按钮输入框中的数量加1,同时可以计算出商品小计,和购物 车总价*/
$scope.jia=function (index) {
$scope.arr[index].number++;
}
/*当点击”-”按钮时输入框中的数量减1,商品小计和总价*/
$scope.jian=function (index) {
if($scope.arr[index].number>){
$scope.arr[index].number--;
}
else if($scope.arr[index].number==){
if(confirm("用户是否删除该商品")){
$scope.arr.splice(index,);
}
}
}
/*计算总价格*/
$scope.allSum=function () {
var allPrice=;
for(var i=;i<$scope.arr.length;i++){
allPrice+=$scope.<span style="color:#660e7a"><strong>arr</strong></span>[<span style="color:#458383">i</span>].<span style="color:#660e7a"><strong>price</strong></span>*$scope.arr[i].number;
}
return allPrice;
};
/*清空购物车*/
$scope.alldel=function () {
if($scope.arr.length==){
alert("您的购物车已空");
}else{
$scope.arr=[];
}
}
/*用户点击第一个checkbox代表全选,全选商品后点击删除选中商品,选中商品被删除, 若购物车商品被全部删除后*/
$scope.allCheck=false;
$scope.allx= function () {
for(var i=;i<$scope.arr.length;i++){
if($scope.allCheck==true){
$scope.arr[i].state=true;
}else {
$scope.arr[i].state=false;
}
}
};
/*每个复选框*/
$scope.itemCheck = function () {
var flag = ;
for(var i = ; i<$scope.arr.length; i++){
if($scope.arr[i].state == true){
flag ++;
}
}
if(flag == $scope.arr.length){
$scope.allCheck = true;
}else{
$scope.allCheck = false;
}
};
/*批量删除*/
$scope.pi=function () {
for(var i=;i<$scope.arr.length;i++){
if($scope.arr[i].state==true){
$scope.arr.splice(i,);
i--;
$scope.allCheck = false;
}
}
}
});
</script>
</head>
<body ng-app="my" ng-controller="mys">
<div class="box">
<h2>我的购物车</h2>
</div>
<div class="box1">
<button ng-click="alldel()" style="margin-right: 10px">清空购物车</button><button ng-click="pi()" style="margin-left: 5px">批量删除</button>
</div>
<div class="box2">
<table border="">
<tr>
<th><input type="checkbox" ng-model="allCheck" ng-click="allx()"/></th>
<th>name</th>
<th>price</th>
<th>number</th>
<th>totalPrice</th>
<th>option</th>
</tr>
<!--用ng-repaet指令将对象遍历并渲染到页面中-->
<tr ng-repeat="item in arr">
<td><input type="checkbox" ng-model="item.state" ng-click="itemCheck()"/></td>
<td>{{item.name}}</td>
<td>{{item.price | currency:"¥:"}}</td>
<td><button ng-click="jian($index)">-</button>
<input type="text" value="{{item.number}}" style="width: 30px;padding-left: 20px"/>
<button ng-click="jia($index)">+</button>
</td>
<td>{{item.price*item.number | currency:"¥:"}}</td>
<td><button ng-click="del($index)">删除</button></td>
</tr>
<tr>
<td colspan="">总金额<span ng-bind="allSum()|currency:'¥:'"></span></td>
</tr>
</table>
</div>
</body>
</html>

(网页)angular js 终极购物车(转)的更多相关文章

  1. (网页)Angular.js 中 copy 赋值与 = 赋值 区别

    转自st.gg Angular.js 中 copy 赋值与 = 赋值 区别 为什么用 $scope.user = $scope.master; $scope.master 会跟着 $scope.use ...

  2. (翻译)Angular.js为什么如此火呢?

    在本文中让我们来逐步发掘angular为什么如此火: Angular.js 是一个MV*(Model-View-Whatever,不管是MVC或者MVVM,统归MDV(model Drive View ...

  3. Angular JS学习之指令

    1.Angular JS通过称为指令的新属性来扩展HTML:通过内置的指令来为应用添加功能: 2.AngularJS指令:AngularJS指令是扩展的HTML属性,带有前缀ng-: **ng-app ...

  4. Angular.js为什么如此火呢?

    在本文中让我们来逐步发掘angular为什么如此火: Angular.js 是一个MV*(Model-View-Whatever,不管是MVC或者MVVM,统归MDV(model Drive View ...

  5. angular.js学习

    1.第一个小例子 <!DOCTYPE html> <html> <body> <div ng-app=""> <p>在输 ...

  6. Angular JS 学习笔记(二)

    1. AngularJS 是一个 JavaScript 框架.它可通过 <script> 标签添加到 HTML 页面.AngularJS 通过 指令 扩展了 HTML,且通过 表达式 绑定 ...

  7. 什么是Angular JS?

    Angular JS学习笔记——什么是Angular JS? Angular JS是一个由Google维护的开源的Javascript框架,主要作者为: Misko Hevery(angular JS ...

  8. angular.js——小小记事本3

    app.js部分,首先是路由.这个之前讲过了,链接在这里—— http://www.cnblogs.com/thestudy/p/5661556.html var app = angular.modu ...

  9. angular.js之路由的选择

    在一个单页面中,我们可以添加多个模块,使得网页只在需要的时候加载这个模块.模块的切换大致上可以代替网页的切换,于是,我们便可以通过模块的切换实现网页的切换,这个切换是按需加载的. 乍一看非常普通的东西 ...

随机推荐

  1. ubuntu 16.04下源码安装opencv3.4

    源码安装opencv,遇到了一些小波折,这里做个备忘吧. 首先要下载源码,路径: https://github.com/opencv/opencv 下载成功后,在opencv的根目录下执行下面操作: ...

  2. SeaweedFS上手使用指南

    SeaweedFS是基于go语言开发的高可用文件存储系统,主要特性 1.成存储上亿的文件(最终受制于你的硬盘大小)2.速度快,内存占用小 上手使用比fastDFS要简单很多,自带Rest API. S ...

  3. Selenium3 + Python3自动化测试系列一——安装Python+selenium及selenium3 浏览器驱动

    一.安装Python https://www.python.org/downloads/ 验证Python是否安装成功.打开Windows命令提示符(cmd),输入python,回车 注意:在安装的过 ...

  4. python 牛客网 你的输出为:空。请检查一下你的代码,有没有循环输入处理多个case。问题解决

    你的输出为:空.请检查一下你的代码,有没有循环输入处理多个case.点击查看如何处理多个case 核心:他这个程序测试正确与否的流程是 连续输入多组测试数据进行测试,只有每组数据都对才行 所以必须使用 ...

  5. tf.nn.in_top_k原理探究

    import tensorflow as tf; A = [[0.8,0.6,0.3], [0.1,0.6,0.4],[0.5,0.1,0.9]] B = [0,2,1] out = tf.nn.in ...

  6. Windows下memcache的配置和使用(python)

    1.memcache的安装和配置: 下载memcache  for windows: http://up.2cto.com/2012/0522/20120522094758371.rar 解压到指定目 ...

  7. Eclipse 工程目录下的.classpath、.project文件和.settings文件作用

    1..classpath 定义了你这个项目在编译时所使用的$CLASSPATH (注: 每次在更新jar的版本或者增加jar之后,请在SVN提交.classpath文件,否则工程的build path ...

  8. 和我一起打造个简单搜索之SpringDataElasticSearch关键词高亮

    前面几篇文章详细讲解了 ElasticSearch 的搭建以及使用 SpringDataElasticSearch 来完成搜索查询,但是搜索一般都会有搜索关键字高亮的功能,今天我们把它给加上. 系列文 ...

  9. TCP编程实践小结1

    说起TCP/IP协议,大家估计都能说出个一二,但是估计很少有人能够深入的理解这个协议,原因有这么几个: 协议本身确实复杂 入门教材没选对,太抽象了,导致大家浅尝辄止 学习过程中如果没有配合实践理解,过 ...

  10. h5活动页开发总结记录

    前几天在做h5活动页面的时候,有这样一个需求 上面的活动排行点击查看历史排行数据,弹出日期选择框,如下图 点击要查看的日期排行数据,这里需要对还没到的日期做处理,让用户不能选择,只可选择今天或者之前的 ...