AngularJS 页面计算

<div ng-app="multipliedCaculateApp" ng-controller="multipliedCaculateController as vm">
    <div class="form-group col-md-4">
        <label><span class="red">*</span>单价(元):</label>
        <input type="text" class="form-control width-60" ng-change="vm.getTotalPrice()"
               ng-model="vm.editResource.unitPrice"/>
    </div>
    <div class="form-group col-md-4">
        <label><span class="red">*</span>数量:</label>
        <input type="text" class="form-control width-60" ng-change="vm.getTotalPrice()"
               ng-model="vm.editResource.listingNumber"/>
    </div>
    <div class="form-group col-md-4">
        <label><span class="red">*</span>总价(元):</label>
        <input type="text" disabled ng-model="vm.editResource.totalPrice" 
               required class="form-control width-60" />
    </div>
</div>
<script src="~/Scripts/angular.min.js"></script>
<script>
        var mainApp = angular.module("multipliedCaculateApp", []);
        mainApp.controller('multipliedCaculateController', function ($scope) {
            debugger;
            var vm = this;
            //editResource是个object  可以不给unitPrice和listingNumber赋默认值
            vm.editResource = {
                unitPrice:1,
                listingNumber:2
            };
            vm.getTotalPrice = function () {
                vm.editResource.totalPrice =vm.editResource.unitPrice * vm.editResource.listingNumber;
            }
            vm.getTotalPrice();
        });
</script>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容