NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
~~~ <body ng-app="example" ng-controller="con1"> <table border="1" width="500"> <tr> <td>商品名称:</td> <td>商品价格:</td> <td>商品数量:</td> <td>总价格:</td> </tr> <tr> <td>{{data.item.name}}</td> <td>{{data.item.price}}</td> <td>{{data.item.num}}</td> <td>{{data.item.num*data.item.price}}</td> <td> <button ng-click="data.add()">添加一件</button> </td> <td> <button ng-click="data.del()">减少一件</button> </td> </tr> </table> </body> ~~~ ~~~ var m = angular.module('example', []); m.controller('con1', ["$scope", function ($scope) { $scope.data = { item: {'name': "apple", 'price': 200, 'num': 2}, add: function () { $scope.data.item.num = Math.min(++$scope.data.item.num, 6); }, del: function () { $scope.data.item.num = Math.max(--$scope.data.item.num, 0); } } }]); ~~~ ![](https://box.kancloud.cn/be3281aebe47315db5b8c7eabbabf625_689x100.png)