实现简单购物车

<!DOCTYPE html>
<html>


<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
<style>
span {
color: orange;
}
</style>
</head>


<body ng-app="MyApp" ng-controller="MyCont">
<table>
<tr>
<td><input type="checkbox" ng-model="q1" ng-checked="ck" ng-click="dian()" /></td>
<td><img src="img/aa.png" /></td>
<td>哈哈阿斯达所大所多<br/><span>150</span><br/><input type="button" value="+" ng-click="aa()" />{{i1}}<input type="button" value="-" ng-click="dd()" /></td>
</tr>
<tr>
<td><input type="checkbox" ng-model="q2" ng-checked="ck" ng-click="dian1()" /></td>
<td><img src="img/bb.png" /></td>
<td>嘿嘿都大傻吊阿萨德<br/><span>119</span><br/><input type="button" value="+" ng-click="bb()" />{{i2}}<input type="button" value="-" ng-click="ee()" /></td>
</tr>
<tr>
<td><input type="checkbox" ng-model="q3" ng-checked="ck" ng-click="dian2()" /></td>
<td><img src="img/cc.png" /></td>
<td>呵呵阿收到了吗sad<br/><span>120</span><br/><input type="button" value="+" ng-click="cc()" />{{i3}}<input type="button" value="-" ng-click="ff()" /></td>
</tr>
</table>
<br />
<input type="checkbox" ng-model="ck" ng-click="quan()"/>全选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 合计:¥
<span>{{one*150+two*119+three*120}}</span><input type="button" value="结算" />
<script>
var mo = angular.module("MyApp", []);
mo.controller("MyCont", function($scope) {
$scope.i1=0;
$scope.i2=0;
$scope.i3=0;
$scope.one = $scope.i1;
$scope.two = $scope.i2;
$scope.three = $scope.i3;
var flag1=false;
var flag2=false;
var flag3=false;
$scope.dian = function() {
if($scope.q1) {
flag1=true;
$scope.one=$scope.i1
}else{
flag1=false;
$scope.one = 0;
}

}
$scope.dian1 = function() {
if($scope.q2) {
flag2=true;
$scope.two=$scope.i2
}else{
flag2=false;
$scope.two = 0;
}
}
$scope.dian2 = function() {
if($scope.q3) {
flag3=true;
$scope.three=$scope.i3
}else{
flag3=false;
$scope.three = 0;
}
}
$scope.quan=function(){
if($scope.ck){
$scope.one=$scope.i1
$scope.two=$scope.i2
$scope.three=$scope.i3
flag1=true;
flag2=true;
flag3=true;
}else{
$scope.one=0;
$scope.two = 0;
$scope.three = 0;
flag1=false;
flag2=false;
flag3=false;
}
}

$scope.aa = function() {
if(flag1){
$scope.one=$scope.one+1;
}
$scope.i1 = $scope.i1 + 1;
}
$scope.dd = function() {
if(flag1){
if($scope.one > 0) {
$scope.one = $scope.one - 1;
}
}else{
if($scope.i1 > 0) {
$scope.i1 = $scope.i1 - 1;
}
}

}
$scope.bb = function() {
if(flag2){
$scope.two=$scope.two+1;
}
$scope.i2 = $scope.i2 + 1;
}
$scope.ee = function() {
if(flag2){
if($scope.two > 0) {
$scope.two = $scope.two - 1;
}
}else{
if($scope.i2 > 0) {
$scope.i2 = $scope.i2 - 1;
}
}

}
$scope.cc = function() {
if(flag3){
$scope.three=$scope.three+1
}
$scope.i3 = $scope.i3 + 1;
}
$scope.ff = function() {
if(flag3){
if($scope.three > 0) {
$scope.three = $scope.three - 1;
}
}else{
if($scope.i3 > 0) {
$scope.i3 = $scope.i3 - 1;
}
}

}
})

</script>
</body>


</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值