练习购物车

先去下载Bootstrap;  下载好bootstrap3文件后, 把里面的css,fonts,js三个文件copy进vendor下新建的bootstrap3文件夹

在<head>

<link rel="stylesheet" href="../../vendor/bootstrap3/css/bootstrap.min.css">
/head>


先把简单的架构搭起来:

要想使用bootstrap,首先在body里面加入“ ng-app="" ”。

Angular关于ng-app的解释:

Use this directive to auto-bootstrap an AngularJS application. The ngApp directive designates the root element of the application and is typically placed near the root element of the page - e.g. on the <body> or<html> tags.

Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. To run multiple applications in an HTML document you must manually bootstrap them using angular.bootstrap instead. AngularJS applications cannot be nested within each other.

You can specify an AngularJS module to be used as the root module for the application. This module will be loaded into the $injectorwhen the application is bootstrapped and should contain the application code needed or have dependencies on other modules that will contain the code. See angular.module for more information.

In the example below if the ngApp directive were not placed on the html element then the document would not be compiled, theAppController would not be instantiated and the {{ a+}} would not be resolved to 3.

ngApp is the easiest, and most common, way to bootstrap an application.

<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../../vendor/bootstrap3/css/bootstrap.min.css">
<body ng-app="">
    <div ng-controller="cartController" class="container">
        <table class="table">
            <thead>
                <tr>
                    <th>产品编号</th>
                    <th>产品名字</th>
                    <th>购买数量</th>
                    <th>产品单价</th>
                    <th>产品总价</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
//用循环遍历的方式(ng-repeat="item in cart"),将JS里面的值放进对应的table。
                <tr ng-repeat="item in cart">
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.quantity}}</td>
                    <td>{{item.price}}</td>
                    <td>{{item.price * item.quantity}}</td>
                    <td>
		//在bootstrap的官网中的CSS里找到想要的button
                       <button type="button" class="btn btn-danger">移除</button>
                    </td>
                </tr>
<tr>
    <td>
        总购买价
    </td>
    <td>
        {{totalPrice()}}
    </td>
    <td>
        总购买数量
    </td>
    <td>
        {{totalQuantity()}}
    </td>
    <td colspan="2">
        <button type="button" class="btn btn-danger">清空购物车</button>
    </td>
            </tbody>
        </table>
    </div>
    <script type="text/javascript" src="app/index.js"></script>
<script type="text/javascript" src="../../vendor/angular/angularjs.js"></script>
</body>
</html>


JS页面:




var cartController = function($scope){
    $scope.cart = [
        {
            id:1000,
            name: 'iPhone5s',
            quantity:'3',
            price:4300
        },
        {
            id:3300,
            name: 'iPhone5',
            quantity:'30',
            price:3300
        },
        {
            id:232,
            name: 'iMac',
            quantity:'4',
            price:23000
        },
        {
            id:1000,
            name: 'iPad',
            quantity:'5',
            price:6900
        }
    ];
//计算出产品的总数量和总价
/**
*  用forEach遍历出属性并加以操作
* angular.forEach($scope.cart,function(item){
*       ...;
*    })
*
*
**/
	
$scope.totalPrice = function(){
    var total= 0;
    angular.forEach($scope.cart,function(item){
        total += item.quantity * item.price;
    })
    return total;
}

$scope.totalQuantity = function(){
    var total = 0;
    angular.forEach($scope.cart,function(item){
        total += item.quantity;
    })
    return total;
}
}

效果如下图:



阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在线商城购物测试用例可以从以下几个方面考虑: 1. 界面测试: - 确保购物页面的布局合理且完整,包括商品信息、价格、数量等显示。 - 确保页面的功能按钮正常显示,如结算、删除、修改数量等。 - 检查购物页面的连接是否正常,如商品详情页、结算页面等。 - 确保购物中的失效宝贝以及其他相关信息正常显示。 2. 功能测试: - 确保用户可以添加商品到购物,无论是否登录。 - 对于未登录用户添加商品到购物后登录,确认商品是否合并到用户购物。 - 如果不允许未登录用户添加商品到购物,检查用户是否收到相应的登录提示。 - 确保购物内商品价格正确显示,包括用户会员折扣。 - 确保勾选商品后,已选商品的总价和优惠活动正确显示。 - 确保勾选商品后,点击结算按钮能进入确认订单信息页面。 - 确保可以对购物中的商品进行信息的修改和规格的变更,并能成功保存。 - 确保购物管理功能正常,包括商品的删除、添加、编辑等操作。 3. 性能测试: - 检查打开购物页面的时间是否在用户可接受的范围内。 - 检查编辑购物、删除和添加商品所需的时间。 - 确保结算金额能实时显示。 - 检查清空失效商品所需的时间。 4. 兼容性测试: - 在不同型号和操作系统下(如iOS和安卓)测试应用的功能是否正常运行。 5. 网络环境测试: - 在不同网络环境下(如3G、4G、WiFi)测试应用的各功能是否正常运行。 - 检查在网络异常情况下是否会有相关的提醒,并测试数据的恢复和加载情况。 6. 异常测试: - 模拟没有内存的情况,检查应用是否能正常响应。 - 测试横竖屏切换时页面展示是否正常。 - 模拟网络中断和频繁操作某一功能,检查是否会导致闪退。 - 在接入电话、短信和社交软件等信息提示时,测试应用是否能正常运行。 通过以上测试用例,可以全面评估在线商城购物的功能和性能,确保用户能够顺畅地使用购物功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [【测试用例练习】测试购物(含思路)](https://blog.csdn.net/qq_40181927/article/details/124642059)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [淘宝购物的测试用例](https://blog.csdn.net/matilda_art/article/details/107922261)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xupeng1986

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值