angularJs-购物金额实例操作

<!DOCTYPE html>
<html ng-app = "myApp">
    <head>
       <meta charset="UTF-8">
       <title></title>
       <style type="text/css">
           
       </style>
    </head>
    <body>
       <div class="box" ng-controller = "myCtrl">
           <p>价格:<input type="text" ng-model = "goods.price"/></p>
           <p>个数:<input type="text" ng-model = "goods.num"/></p>
           <p>运费:<span>{{goods.fee}}</span></p>
           <p>费用:<span>{{fnNum() | currency : "¥"}}</span></p>
       </div>
    </body>
    <script src="angular.min.js"></script>
    <script src="angular-route.min.js"></script>
    <script src="angular-ui-router.min.js"></script>
    <script type="text/javascript">
       var myApp = angular.module("myApp",[]);
       myApp.controller("myCtrl",function($scope){
           $scope.goods = {
              price:5,
              num:1,
              fee:10
           }
           $scope.fnNum = function(){
              return $scope.goods.price*$scope.goods.num
           }
           $scope.$watch($scope.fnNum,function(newFee){
              if (newFee>=100) {
                  $scope.goods.fee = 0 ;
              }else{
                  $scope.goods.fee = 10 ;
              }
           })
       })
    </script>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值