js购物车
来源:互联网 发布:excel取消数据验证 编辑:程序博客网 时间:2024/06/06 19:59
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>购物车</title>
<link rel="stylesheet" href="js/bootstrap.min.css" />
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-2.1.0.js"></script>
<style>
span{padding-left:50px;padding-right:60px;}
</style>
<script>
var app=angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
//声明数据对象,初始化商品信息
$scope.shopList=[
{ name:'单片机',price:'80.90',num:1},
{ name:'电烙铁',price:'20.40',num:1},
{ name:'万用表',price:'46.90',num:1},
{ name:'示波器',price:'21.10',num:1},
{ name:'电饭锅',price:'79.30',num:1}
];
//点击减少
$scope.reduce= function (index) {
if($scope.shopList[index].num>1){
$scope.shopList[index].num--;
}else{
$scope.remove(index);
}
};
//点击增加
$scope.add=function(index){
$scope.shopList[index].num++;
};
//计算总价
$scope.allSum=function(){
var allPrice = 0;
for(var i= 0;i<$scope.shopList.length;i++){
allPrice+=$scope.shopList[i].price*$scope.shopList[i].num;
}
return allPrice;
};
//计算总数量
$scope.allNum=function(){
var allShu=0;
for(var i=0;i<$scope.shopList.length;i++){
allShu+=$scope.shopList[i].num;
}
return allShu;
};
//移除一项
$scope.remove=function(index){
if(confirm('您是否将商品移除购物车?')){
$scope.shopList.splice(index,1);
}
};
//使得输入框中不得小于等于0
$scope.change=function(index){
if($scope.shopList[index].num>=1){
}else{
$scope.shopList[index].num=1;
}
};
//清空购物车
$scope.removeAll=function(){
if(confirm('确定清空购物车')){
$scope.shopList=[];
}
}
});
</script>
</head>
<body ng-app="myApp">
<div class="container">
<h1>我的购物车</h1>
<div ng-controller="myCtrl">
<button class="btn btn-warning "ng-click="removeAll()" style="background-color:#D9534F; color: white; margin-left:1000px;">清空购物车</button>
<ul class="list-group">
<li class="list-group-item">
<span><input type="checkbox" ng-model="select_all"/></span>
<span>name</span>
<span>price</span>
<span>number</span>
<span>totalPrice</span>
<span>option</span>
</li>
<li ng-repeat="shop in shopList" class="list-group-item">
<span><input ng-model="select_all" type="checkbox" /></span>
<span>{{shop.name}}</span>
<span>{{shop.price|currency : '¥'}}</span>
<span>
<button ng-click="reduce($index)" style="background-color:#337AB7;">-</button>
<input type="text" placeholder="请输入大于0的数" ng-model="shop.num" ng-change="change($index)" style="width: 30px;">
<button ng-click="add($index)" style="background-color:#337AB7;">+</button>
</span>
<span>{{shop.price*shop.num|currency : '¥'}}</span>
<button class="btn btn-primary btn-xs" ng-click="remove($index)" style="background-color:#337AB7;">删除</button>
</li>
<li class="list-group-item">总价为:¥<span ng-bind="allSum()"></span></li>
</ul>
</div>
</div>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title>购物车</title>
<link rel="stylesheet" href="js/bootstrap.min.css" />
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-2.1.0.js"></script>
<style>
span{padding-left:50px;padding-right:60px;}
</style>
<script>
var app=angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
//声明数据对象,初始化商品信息
$scope.shopList=[
{ name:'单片机',price:'80.90',num:1},
{ name:'电烙铁',price:'20.40',num:1},
{ name:'万用表',price:'46.90',num:1},
{ name:'示波器',price:'21.10',num:1},
{ name:'电饭锅',price:'79.30',num:1}
];
//点击减少
$scope.reduce= function (index) {
if($scope.shopList[index].num>1){
$scope.shopList[index].num--;
}else{
$scope.remove(index);
}
};
//点击增加
$scope.add=function(index){
$scope.shopList[index].num++;
};
//计算总价
$scope.allSum=function(){
var allPrice = 0;
for(var i= 0;i<$scope.shopList.length;i++){
allPrice+=$scope.shopList[i].price*$scope.shopList[i].num;
}
return allPrice;
};
//计算总数量
$scope.allNum=function(){
var allShu=0;
for(var i=0;i<$scope.shopList.length;i++){
allShu+=$scope.shopList[i].num;
}
return allShu;
};
//移除一项
$scope.remove=function(index){
if(confirm('您是否将商品移除购物车?')){
$scope.shopList.splice(index,1);
}
};
//使得输入框中不得小于等于0
$scope.change=function(index){
if($scope.shopList[index].num>=1){
}else{
$scope.shopList[index].num=1;
}
};
//清空购物车
$scope.removeAll=function(){
if(confirm('确定清空购物车')){
$scope.shopList=[];
}
}
});
</script>
</head>
<body ng-app="myApp">
<div class="container">
<h1>我的购物车</h1>
<div ng-controller="myCtrl">
<button class="btn btn-warning "ng-click="removeAll()" style="background-color:#D9534F; color: white; margin-left:1000px;">清空购物车</button>
<ul class="list-group">
<li class="list-group-item">
<span><input type="checkbox" ng-model="select_all"/></span>
<span>name</span>
<span>price</span>
<span>number</span>
<span>totalPrice</span>
<span>option</span>
</li>
<li ng-repeat="shop in shopList" class="list-group-item">
<span><input ng-model="select_all" type="checkbox" /></span>
<span>{{shop.name}}</span>
<span>{{shop.price|currency : '¥'}}</span>
<span>
<button ng-click="reduce($index)" style="background-color:#337AB7;">-</button>
<input type="text" placeholder="请输入大于0的数" ng-model="shop.num" ng-change="change($index)" style="width: 30px;">
<button ng-click="add($index)" style="background-color:#337AB7;">+</button>
</span>
<span>{{shop.price*shop.num|currency : '¥'}}</span>
<button class="btn btn-primary btn-xs" ng-click="remove($index)" style="background-color:#337AB7;">删除</button>
</li>
<li class="list-group-item">总价为:¥<span ng-bind="allSum()"></span></li>
</ul>
</div>
</div>
</body>
</html>
阅读全文
0 0
- JS+COOKIE购物车
- js购物车
- js购物车
- 购物车js代码
- 购物车(JS代码)
- js实现购物车
- 购物车car.js
- angular.js 购物车
- js购物车
- js购物车
- 购物车JS
- 购物车js页面
- angular.js 购物车
- js+cookie+servlet(购物车)
- JS实现的购物车
- 存js版购物车
- js加入购物车动画
- js--购物车加减效果
- 数据结构与算法(Java描述)-13、对象数组以及MyVector类、MySet类实现
- 图解Android和Linux发行版的区别
- 爬取新浪、网易、今日头条、UC四大网站新闻标题及内容
- java 如何读取配置文件
- 662. Maximum Width of Binary Tree
- js购物车
- mysql5.17组复制安装
- oracle中sequence详解
- Android Okhttp缓存:精细化每一个Request的CacheControl缓存控制策略(二)
- 2006年培养学员8万人,每年增长%25,请问按此增长速度,到那一年培训学员人数将达到20万人用for,while,dowhile,实现
- ansible inventory.py 脚本
- mysql数据库show tables 显示表名,但是查询的时候却提示此表不存在
- UEditor 富文本编辑器拓展之-----上传图片至项目之外或资源服务器
- 解决使用tf.slim找不到slim.utils函数问题