<!DOCTYPE html>
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js捐赠管理</title>
<link href="https://www.jb51.net/css/css.css" type="text/css" />
<script type="text/javascript">
//受捐单位数组
var listOrgs = [
{ "id": "1", "comName": "壹基金" },
{ "id": "2", "comName": "宋庆龄基金" },
{ "id": "3", "comName": "慈济基金" },
{ "id": "4", "comName": "红十字会" },
{ "id": "5", "comName": "狼图腾" }
];
//给listOrgs数组对象动态添加一个匿名方法
listOrgs.getOrgsById = function (id) {
for (var i = 0; i < listOrgs.length; i++) {
if (listOrgs[i].id == id) {
return listOrgs[i];//返回一个对象
}
}
};
//捐款数据数组
var listData = [
{ "id": "1", "perName": "成龙", "orgId": "1", "money": "10000", "date": "2012-3-3" },
{ "id": "2", "perName": "李连杰", "orgId": "2", "money": "10000", "date": "2012-3-3" },
{ "id": "3", "perName": "陈光标", "orgId": "3", "money": "10000", "date": "2012-3-3" },
{ "id": "4", "perName": "胡锦涛", "orgId": "1", "money": "10000", "date": "2012-3-3" },
{ "id": "5", "perName": "周星池", "orgId": "2", "money": "10000", "date": "2012-3-3" },
{ "id": "6", "perName": "黎明", "orgId": "3", "money": "10000", "date": "2012-3-3" },
{ "id": "7", "perName": "狼人", "orgId": "3", "money": "10000", "date": "2012-3-3" },
{ "id": "8", "perName": "狂魔", "orgId": "3", "money": "10000", "date": "2012-3-3" },
{ "id": "9", "perName": "三疯", "orgId": "3", "money": "10000", "date": "2012-3-3" }
];
//分页查询数组
listData.fenyeQuery = function (pageNow, pageSize) {
var res = new Array();
//1.按pageSize为5,第1页就是listData[0]-listData[4],第2页就是listData[5]-listData[9]
//第3页就是listData[10]-listData[14]
var start = (pageNow - 1) * pageSize;
var end = listData.length > (pageNow * pageSize) ? (pageNow * pageSize) : listData.length;
for (var i = start ; i < end; i++) {
res[res.length] = listData[i];
}
return res;
};
listData.queryByOrId = function (orid) {
var arr = new Array();
for (var i = 0; i < listData.length; i++) {
if (listData[i].orgId == orid) {
arr[arr.length] = listData[i];
}
}
return arr;
};
listData.idNum = listData.length;
listData.addRec = function(rec) {
listData.idNum++;
var newRec = { "id": listData.idNum, "perName": rec.perName, "orgId": rec.orgId, "money": rec.money, "date": rec.date };
listData[listData.length] = newRec;
return newRec;
};
js实现的捐赠管理完整实例
内容版权声明:除非注明,否则皆为本站原创文章。