angularjs 动态计算平均值
<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title></title>
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) { $scope.goods = [{
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}, {
num: 1,
price: 10
}];
//总计
$scope.allPrice = 0;
$scope.getAllPrice = function() {
var count = 0;
$scope.good = $scope.goods.filter(function(e) {
return e.price != '' && e.price != 0 && e.price != null;
});
for(index in $scope.good) {
count += parseInt($scope.good[index].price);
}
$scope.allPrice = count / $scope.good.length;
}
$scope.getAllPrice(); });
</script>
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none !important;
}
</style> </head> <body ng-app="myApp" ng-controller="myCtrl">
<center>
<table border="1px">
<tr>
<td>价格</td>
</tr>
<tr ng-repeat="g in goods">
<td>
<span ng-show="g.flag">{{g.price}}</span>
<input ng-hide="g.flag" ng-model="g.price" ng-change="getAllPrice()" type="number" />
</td>
</tr>
</table><br /> 平均价:
<span>{{allPrice}}</span>
</center>
</body> </html>
angularjs 动态计算平均值的更多相关文章
- 动态计算UITableViewCell高度
动态计算UITableViewCell高度 UILabel in UITableViewCell Auto Layout - UILabel的属性Lines设为了0表示显示多行.Auto Layout ...
- 动态计算Label高度
//1.设置该label的numberOfLines为0 self.titleLabel.numberOfLines = 0; //2.字体的设置要与之前相同 NSDictionary * at ...
- iOS 动态计算文本内容的高度
关于ios 下动态计算文本内容的高度,经过查阅和网上搜素,现在看到的有以下几种方法: 1. // 获取字符串的大小 ios6 - (CGSize)getStringRect_:(NSString* ...
- angular.element方法汇总以及AngularJS 动态添加元素和删除元素
addClass()-为每个匹配的元素添加指定的样式类名after()-在匹配元素集合中的每个元素后面插入参数所指定的内容,作为其兄弟节点append()-在每个匹配元素里面的末尾处插入参数内容att ...
- 还能输入多少字?(JS动态计算)
<div class="m-form ovh"> <div class="hd"> <span class="fr&qu ...
- iOS学习之根据文本内容动态计算文本框高度的步骤
在视图加载的过程中,是先计算出frame,再根据frame加载视图的,所以在设计计算高度的方法的时候,设计成加号方法; //首先给外界提供计算cell高度的方法 + (CGFloat)heightFo ...
- matlab 利用while循环计算平均值和方差
一.该程序是用来测输入数据的平均值和方差的 公式: 二. 项目流程: 1. State the problem假定所有测量数为正数或者0,计算这一系列测量数的平均值和方差.假定我们预先不知道有多少测量 ...
- 理解rem实现响应式布局原理及js动态计算rem
前言 移动端布局中,童鞋们会使用到rem作为css单位进行不同手机屏幕大小上的适配.那么来讲讲rem在其中起的作用和如何动态设置rem的值. 1.什么是rem rem是相对于根元素(html标签)的字 ...
- iOS中动态计算不同颜色、字体的文字高度
在改项目bug的时候,有一个问题动态计算label的高度,前开发者竟然用字符串长度除以14.16这样的常量来计算是否换行,结果cell的高度问题非常严重. 因为label内容里有部分关键字是要另一种颜 ...
随机推荐
- 深度学习-mnist手写体识别
mnist手写体识别 Mnist数据集可以从官网下载,网址: http://yann.lecun.com/exdb/mnist/ 下载下来的数据集被分成两部分:55000行的训练数据集(mnist.t ...
- glib系列1 编译
1 安装 meson glib 使用 meson进行构建,需要python3,首先下载meson, meson/meson.py 就是程序本身了,可以直接运行 git clone https://gi ...
- TZOJ2882: 美食节之感恩父母
#include<stdio.h> int main() { ],b[],i,j,max,m,t1,t2,t3; while(scanf("%d",&m),m) ...
- 使用Python比较MySQL数据库中两个数据库的表结构--转载
https://blog.csdn.net/tenaguan4461/article/details/82286781 https://www.jianshu.com/p/b3dac5a3479a
- phc-winner-argon2、argon2-cffi安装使用方法
Argon2 is a password-hashing function created by by Alex Biryukov, Daniel Dinu, and Dmitry Khovratov ...
- [Python爬虫] 使用 Beautiful Soup 4 快速爬取所需的网页信息
[Python爬虫] 使用 Beautiful Soup 4 快速爬取所需的网页信息 2018-07-21 23:53:02 larger5 阅读数 4123更多 分类专栏: 网络爬虫 版权声明: ...
- MySQL中的索引详讲(转)
https://www.cnblogs.com/whgk/p/6179612.html
- (九)二进制文件在webservice中的处理(以DataHandler方式)
一.需求 1. 客户端从服务端下载附件 2. 客户端上传附件到服务端 二.案例 本章通过DataHander的方式来进行传递. 注意: 1:接口中要定义@MTOM 2:方法中要使用@XmlMime ...
- vue 集成 NEditor 富文本
下载NEditor 放在 vue 项目下面 public 文件中. 安装 vue-neditor-wrap 执行命令 npm install vue-neditor-wrap 代码使用 ...
- adminMongo:mongoDB node GUI(mongoDB图形化界面)
adminMongo:mongoDB node GUI(mongoDB图形化界面) 获取项目项目 克隆:git clone https://github.com/mrvautin/adminMongo ...