1. 程式人生 > >jsjqueryangular購物車練習

jsjqueryangular購物車練習

購物車練習
//下單操作

" role="presentation" style="position: relative;"> scope.ordermenu=function(id){                      for (var i = 0; i <
scope.menus.length; i++) {
if(
" role="presentation" style="position: relative;"> scope.menus[i].id==id){                              //銷量增加 scope.menus[i].sells+=$scope.menus[i].number;
break;
}
}

            }
            //撤銷操作
            $scope.revmenu=function(id){
                if(confirm("確定撤銷嗎?")){
                    for (var i = 0; i < $scope.menus.length; i++) {
                    if($scope.menus[i].id==id){
                        //銷量減少
                        $scope.menus[i].sells-=$scope.menus[i].number;
                        //清空數量
                        $scope.menus[i].number=0;
                        break;
                    }
                    }
                }




            }

            //數量加加 根據id去查詢數量,然後再改變它的number值
            $scope.increase=function(id){
                for (var i = 0; i < $scope.menus.length; i++) {
                    if($scope.menus[i].id==id){
                        $scope.menus[i].number++;
                        break;
                    }
                }

            }
            //數量的相
            $scope.reduce=function(id){
                for (var i = 0; i < $scope.menus.length; i++) {
                    if($scope.menus[i].id==id){
                        if($scope.menus[i].number==0){
                            alert("不能再減少了。");
                        }else{
                            $scope.menus[i].number--;
                        }
                        break;
                    }
                }

            }