js实现的捐赠管理完整实例(6)

window.onload = function() { 
            //绑定查询 
            LoadOrgList(gel("selSearchOrg")); 
            //绑定受捐赠单位 
            LoadOrgList(gel("selAddOrg")); 
            LoadOrgList(SeleteOrg); 
            //绑定表格和listData 
            LoadDataList(); 

//给新增按钮绑定一个事件 
            gel("btnAdd").onclick = function() { 
                if ((!(gel("txtName").value)) || (!(gel("txtMoney").value) || (!(gel("txtDate").value)))) { 
                    alert("输入不能为空"); 
                    return; 
                } 
 
                //1.得到输入的内容,打包成一个对象(按照listData的格式) 
                var arr = { "perName": gel("txtName").value, "orgId": gel("selAddOrg").value, "money": gel("txtMoney").value, "date": gel("txtDate").value }; 
                //2.添加到listData数组中 
                var res = listData.addRec(arr); 
                //3.显示在表格中 
                var trnew = gel("tbList").insertRow(-1); 
                trnew.insertCell(-1).innerHTML = res.id; 
                trnew.insertCell(-1).innerHTML = res.perName; 
 
                var tdOrg = trnew.insertCell(-1); 
                tdOrg.setAttribute("orgId", res.orgId); 
                tdOrg.innerHTML = listOrgs.getOrgsById(res.orgId).comName; 
                trnew.insertCell(-1).innerHTML = res.money; 
                trnew.insertCell(-1).innerHTML = res.date; 
                trnew.insertCell(-1).innerHTML = "<a href='#' >删除</a> <a href='#'>修改</a>"; 
            }; 
 
            //给查询按钮绑定事件 
            gel("btnSearch").onclick = function () { 
                if (gel("selSearchOrg").value == -1) { 
                    return; 
                } 
 
                //1.获取要查询的受捐赠单位的orgid 
                var orgId = gel("selSearchOrg").value; 
                //2.在ListData数组中定义一个根据orgid查询的方法,并在这里调用 
                var arrRes = listData.queryByOrId(orgId); 
                //3.将旧的表格数据移除显示,一定要从下到上清空显示 
                var trs = gel("tbList").rows; 
 
                for (var j = trs.length-1; j>0; j--) { 
                    gel("tbList").deleteRow(j); 
                } 
                //4.显示新的数据arrRes 
                for (var i = 0; i < arrRes.length; i++) { 
                    addRow(arrRes[i]); 
                }  
            }; 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxwww.html