• lianxi


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .clear:after{
                content: "";
                display: block;
                 0;
                height: 0;
                clear: both;
            }
            li{
                list-style: none;
                 700px;
            }
            .left{
                float: left;
            }
            .right{
                float: right;
                margin-top: 50px;
            }
    
        </style>
    
        <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
        <script>
            var myapp=angular.module("myapp",[]);
            myapp.controller("myCtrl",function($scope){
                $scope.data={
                    categories:[{id:"101",category:"商品01"},
                        {id:"102",category:"商品02"},
                        {id:"103",category:"商品03"},
                        {id:"103",category:"商品04"}],
                    //商品明细
                    products:[
                        {category:"商品01",name:"鼠标",desc:"2016春季爆款",price:"101",imgsrc:"../images/TB1_50x50.jpg"},
                        {category:"商品01",name:"键盘",desc:"2016夏季爆款",price:"601",imgsrc:"../images/TB2_50x50.jpg"},
                        {category:"商品01",name:"显示器",desc:"2016春季爆款",price:"101",imgsrc:"../images/TB1_50x50.jpg"},
                        {category:"商品01",name:"硬盘",desc:"2016夏季爆款",price:"601",imgsrc:"../images/TB2_50x50.jpg"},
                        {category:"商品02",name:"主机",desc:"2015春季爆款",price:"101",imgsrc:"../images/TB1_50x50.jpg"},
                        {category:"商品02",name:"音响",desc:"2015夏季爆款",price:"601",imgsrc:"../images/TB2_50x50.jpg"},
                        {category:"商品04",name:"插线板",desc:"2013夏季爆款",price:"601",imgsrc:"../images/TB2_50x50.jpg"}
                    ]
                };
                //添加购物车
                $scope.cart=[];
                $scope.add=function(item){
                    var has=false;
                    for(var i=0;i<$scope.cart.length;i++){
                        if($scope.cart[i].item.name==item.name){
                            has=true;
                            $scope.cart[i].num++;
                            break;
                        }else{
                            has=false;
                        }
                    }
                    if(has==false){
                        $scope.cart.push({item:item,num:1})
                    }
                    //console.log($scope.cart)
                }
            })
        </script>
    </head>
    <body ng-app="myapp" ng-controller="myCtrl">
        <table>
            <thead>
            <tr>
                <th>产品名称</th>
                <th>数量</th>
                <th>价格</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="item in cart">
                <td>{{item.item.name}}</td>
                <td>{{item.num}}</td>
                <td>{{item.item.price}}</td>
            </tr>
            </tbody>
        </table>
        <ul>
            <li class="clear" ng-repeat="item in data.products">
                <div class="left">
                    <h2><span>{{item.name}}</span><span>{{item.category}}</span></h2>
                    <img ng-src="{{item.imgsrc}}"><span>{{item.desc}}</span>
                </div>
                <div class="right">
                    <span>{{item.price|currency:"¥"}}</span><br/>
                    <button ng-click="add(item)">添加到购物车</button>
                </div>
            </li>
        </ul>
    
    </body>
    </html>
  • 相关阅读:
    异常 中断 陷阱
    关于delete字符串 需不需要加 [ ]
    关于联合体输出的问题(是否小端模式)
    String reorder
    数据库 ---5 索引 创建用户及授权 数据备份
    数据库 --- 4 多表查询 ,Navicat工具 , pymysql模块
    数据库 --- 3 行(记录)操作 单表查询
    数据库 --- 2 库 ,表
    数据库 --- 1 初始 数据库
    并发 --- 5 线程的其他方法 线程队列 线程池 协程
  • 原文地址:https://www.cnblogs.com/yangzhewoaini/p/7697982.html
Copyright © 2020-2023  润新知