js动态创建表格、DIV、遮照

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ taglib uri="erptag" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>新增原辅料检验记录</title>
</head>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/popwindow.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/clickdilog.js"></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/include/exestyle.css"/>
<script type="text/javascript">
function tabs(obj){
var tabli = obj.parentNode.parentNode.getElementsByTagName("li");
	for (i=0;i<tabli.length;i++){
		tabli[i].className = "";
		var contentId = tabli[i].id + "_content";
		document.getElementById(contentId).style.display = "none";
	}
	obj.parentNode.className = "selected";
	document.getElementById(obj.parentNode.id + "_content").style.display = "block";
}
window.onload=beforeLoad;
function beforeLoad(){
	$.ajax({
			type:"post",
			url:"beforeAddMaterial.do",
			dataType:"json",
			cache:"false",
			success:function(data){
				initValue(data);
				damAddSelect(data);
			
				
			}
	});
}

function initValue(obj){
	var tranCheckID=document.getElementById("transferCheckID");
		tranCheckID.value=obj.hashMapList[0];
		$("#reportID").val(obj.hashMapList[1]);
		$("#checkDate").val(new Date().toLocaleDateString());
	
}

function damAddSelect(obj){
	for(var i=2;i<obj.hashMapList.length;i++){
		document.getElementById("tcderptment").options.add(new Option(obj.hashMapList[i].TCDEPT,obj.hashMapList[i].TRANSFERCHECKID));
	}
}

</script>
<script type="text/javascript">
		/**
			创建主窗体
		*/
		function createWindow(){
			var flag=false;
			var maskDiv = document.createElement('div');
				maskDiv.className = "mask";
				maskDiv.id = "maskDiv";
				maskDiv.style.position = "absolute";
				maskDiv.style.width = 600 + "px";
				maskDiv.style.height = 300 + "px";
				maskDiv.style.background = "#ffffff";
				maskDiv.style.zIndex ="1";
				maskDiv.style.textAlign = "center";
				maskDiv.style.left = (document.body.offsetHeight/2)+"px";
				maskDiv.style.top = document.body.offsetWidth/20+"px";
				document.body.appendChild(maskDiv);
				createDIV('引送检单','maskDivChild-1','maskDivChild-1','100%','8%','#9EC0E8','maskDiv');
				createDIV('','maskDivChild-2','maskDivChild-2','100%','82%','#ffffff','maskDiv');
				createDIV("<input type='button' value='确认' onclick='saveValue()'/><input type='button' value='关闭' onclick='closeWindow()'/>",
							'maskDivChild-3','maskDivChild-3','100%','10%','#CBCBCC','maskDiv');
				flag=true;
			return flag;
		}
		/**
			DIV标签(主窗体的子标签)
		*/
		function createDIV(html,className,id,width,height,backgroundcolor,parentDivId){
				var maskDivchild = document.createElement('div');
				maskDivchild.className = className;
				maskDivchild.id = id;
				
				maskDivchild.style.width = width ;
				maskDivchild.style.height = height ;
				maskDivchild.style.background = backgroundcolor;
				maskDivchild.innerHTML=html;
				document.getElementById(parentDivId).appendChild(maskDivchild);
		}

		/**
		屏蔽网
		*/
		function showMessage(){
			var ba = document.getElementById("bg");
			var h = document.body.offsetHeight > document.documentElement.offsetHeight ? 
					document.body.offsetHeight : document.documentElement.offsetHeight;
					ba.style.height = h + "px";
					ba.style.display="";
			var flag=createWindow();
			ajaxLoadData();
			return flag;		
		}
		/**
		创建表格
		*/
		function createTable(parentDivId,arr){
			var table = document.createElement('table');   
   			 table.setAttribute("id",'tableID');   
   			 table.setAttribute("className","TableLine");//设定样式   
    		 table.setAttribute("width",'98%');   
    		 table.setAttribute("cellpadding",'3');   
   			 table.setAttribute("cellspacing",'0');   
  
 			var row = table.insertRow();   
    		row.style.setAttribute("backgroundColor","#e0e0e0");   
       
   			 for (var i = 0; i < arr.length; i++) {   
        		 var col = row.insertCell();   
        		 if(i==0){   
         		   col.setAttribute("width",'3%');   
     		    }   
      		   col.setAttribute("className","border:1px solid #9BC2E0;");   
      		   col.setAttribute("align","center");   
       		   col.style.fontSize="13px";   
       		   col.style.fontWeight="Bold";;   
       		   col.innerHTML = arr[i];   
    			}  
			document.getElementById(parentDivId).appendChild(table);
			return table;
		}
		/**
			向表格添加一行记录
		*/
		function addRow(table,id,arr){   
			
 			 var row = table.insertRow();   
  			 row.setAttribute("id",id);   
  			 row.onclick=function (){selectFlagValue(this)};
  			 for(var i=0;i<arr.length;i++){   
   					 var col = row.insertCell();   
    				 col.innerHTML = arr[i];   
      				  //col.innerText = arr[i];   
    				 col.setAttribute("title",arr[i]);   
 				 }   
		}  
		/**
			关闭按钮
		*/
		function closeWindow(){
			var ba = document.getElementById("bg");
			var mainDiv = document.getElementById("maskDiv");
			ba.style.display="none";
			document.body.removeChild(mainDiv);
		}
		
		var selectArr=new Array();
		/**
			确认按钮
		*/
		
		function saveValue(){
			
			$("#STRANSFERCHECKID").val(selectArr[0]);
			$("#BOOKDATE").val(selectArr[1]);
			$("#BMSUNAME").val(selectArr[3]);
			$("#mnum").val(selectArr[4]);
			$("#RDMANAME").val(selectArr[5]);
			$("#SPECS").val(selectArr[6]);
			$("#BATCHCODE").val(selectArr[7]);
			$("#RDMAKNAME").val(selectArr[8]);
			$("#PRODUCEDATE").val(selectArr[9]);
			$("#TRUEAMOUNT").val(selectArr[10]);
			$("#UNIT").val(selectArr[11]);
			$("#REQUESTAMOUNT").val(selectArr[12]);
			$("#AUDITER").val(selectArr[13]);
			$("#STATUS").val(selectArr[14]);
			closeWindow();
		
		}
		/**
			从后台服务器加载数据
		*/
		function ajaxLoadData(){
			$.ajax({
					type:"post",
					url:"loadTransferCheck.do",
					dataType:"json",
					cache:"false",
					success:function(data){
						insertTableData(data);
				}
			});
		}
		
		/**
			将数据插入表格
		*/
		function insertTableData(obj){
				var arr=new Array('送检单号','入库日期','供应商编号','供应商名称','货号','原料名称','规格','批号','类别','生产日期','总数量','单位','入库数据','审批人','审批状态');
				var tab=createTable('maskDivChild-2',arr);
				var arrdata;
				for(var i=0;i<obj.hashMapListTransferCheck.length;i++){
						arrdata=new Array();	
						arrdata[0]=obj.hashMapListTransferCheck[i].TRANSFERCHECKID;
						arrdata[1]=obj.hashMapListTransferCheck[i].BOOKDATE;
						arrdata[2]=obj.hashMapListTransferCheck[i].CODE;
						arrdata[3]=obj.hashMapListTransferCheck[i].BMSUNAME;
						arrdata[4]=obj.hashMapListTransferCheck[i].MNUM;
						arrdata[5]=obj.hashMapListTransferCheck[i].RDMANAME;
						arrdata[6]=obj.hashMapListTransferCheck[i].SPECS;
						arrdata[7]=obj.hashMapListTransferCheck[i].BATCHCODE;
						arrdata[8]=obj.hashMapListTransferCheck[i].RDMAKNAME;
						arrdata[9]=obj.hashMapListTransferCheck[i].PRODUCEDATE;
						arrdata[10]=obj.hashMapListTransferCheck[i].TRUEAMOUNT;
						arrdata[11]=obj.hashMapListTransferCheck[i].UNIT;
						arrdata[12]=obj.hashMapListTransferCheck[i].REQUESTAMOUNT;
						arrdata[13]=obj.hashMapListTransferCheck[i].AUDITER;
						arrdata[14]=obj.hashMapListTransferCheck[i].STATUS;
						addRow(tab,'tabTr',arrdata);
				}
				
		}
		
		/**
			选中Table变色并取出数据
		*/
		function selectFlagValue(obj){
				for(var i=1;i<obj.parentNode.rows.length;i++){
					if(obj.parentNode.rows[i].rowIndex==obj.rowIndex){
							obj.style.background='#96E0E2';
					}else{
						obj.parentNode.rows[i].style.background='white';
					}
				}
				//将Table中选中的某行数据放入数据
				for(var j=0;j<obj.cells.length;j++){
					selectArr[j]=obj.cells[j].innerText;
				}
				
		}
		

	</script>
<style type="text/css">
.tab{
	width:100%;
	float:left;
	margin-left:0px;
}
.tab li{
	float:left;
	margin-right:3px;
	display:inline;
	width:100px;
	border:1px solid #ACA899;
	border-bottom:white;
	text-align:center;
	padding-top:1px;
	font-size:12pt;
}
.tabContent{
	display:none;
	border:1px solid #ACA899;
	height:100%;
}
div ul li{font-size:11pt;font-weight:bold;padding-top:3px;}
a{
	text-decoration : none ;
}
input{font-weight:bold;padding-top:2px;font-size:10pt;}

table tr td{font-size:9pt;padding-top:3px;color:#5B7CAE;}
</style>
<body>
	<form action="addmaterial.do" method="post">
		<div style="width:100%;height:100%;">
			<ul class="tab">
				<li id="checkRecord"><a href="#" onclick="tabs(this)">检验记录</a></li>
				<li id="checkReport"><a href="#" onclick="tabs(this)">检验报告</a></li>
			</ul>
			<div class="tabContent"  id="checkRecord_content" style="display:block;height:350px;">
				<table style="width:100%;" border="0">
					<tr>
						<input type="hidden" name="material.inQuantity" id="REQUESTAMOUNT"/>
						<input type="hidden" name="material.auditer" id="AUDITER"/>
						<input type="hidden" name="material.status" id="STATUS"/>
						<input type="hidden" name="bookDate" id="BOOKDATE"/>
						<td align="right">检验报告单号:</td>
						<td><input type="text" name="material.materialCheckID" id="transferCheckID"/></td>
						<td align="right">货号:</td>
						<td><input type="text"  id='mnum' style="background:#ECE9D8;" /></td>
						<td align="right">原料名称:</td>
						<td><input type="text"  id="RDMANAME" style="background:#ECE9D8;" /></td>
					</tr>
					<tr>
						<td align="right">规格:</td>
						<td><input type="text"  id="SPECS" style="background:#ECE9D8;" /></td>
						<td align="right">批号:</td>
						<td><input type="text" name="material.lotNumber" id="BATCHCODE" style="background:#ECE9D8;" /></td>
						<td align="right">物资类别:</td>
						<td><input type="text"  id="RDMAKNAME" style="background:#ECE9D8;" /></td>
					</tr>
					<tr>
						<td align="right">生产日期:</td>
						<td><input type="text" name="manufactureDate" id="PRODUCEDATE" style="background:#ECE9D8;" /></td>
						<td align="right">供应商:</td>
						<td><input type="text"  id="BMSUNAME" style="background:#ECE9D8;" /></td>
						<td align="right">总数量:</td>
						<td><input type="text" name="material.quantity" id="TRUEAMOUNT" style="background:#ECE9D8;" /></td>
					</tr>
					<tr>
						<td align="right">单位:</td>
						<td><input type="text"  id="UNIT" style="background:#ECE9D8;" /></td>
						<td align="right">抽样数量:</td>
						<td><input type="text" name="material.sampledQuantity"/></td>
						<td align="right">合格数量:</td>
						<td><input type="text" name="material.qualifiedQuantity"/></td>
					</tr>
					<tr>
						<td align="right">检验结果:</td>
						<td>
							<c:resourceselect property="material.checkResult" resourceid="949021">
							</c:resourceselect>
						</td>
						<td align="right">检验日期:</td>
						<td><input type="text" name="checkDate" id="checkDate"  style="background:#ECE9D8;" /></td>
						<td align="right">检验员:</td>
						<td><input type="text" name="material.checker" style="background:#ECE9D8;" /></td>
					</tr>
					<tr>
						<td align="right">制单部门:</td>
						<td><select name="material.deptId" style="width:80px;" id="tcderptment"></select></td>
						<td align="right">原料送检单号:</td>
						<td><input type="text" name="material.transferCheckID" id="STRANSFERCHECKID"  style="background:#ECE9D8;" /></td>
						<td></td>
						<td></td>
					</tr>
					<tr>
						<td>检验情况:</td>
						<td colspan="5">
							<textarea name="material.checkCondition" style="width:100%;height:60px;" rows="" cols=""></textarea>
							
						</td>
						
					</tr>
					<tr>
						<td>备注:</td>
						<td colspan="5">
							<textarea name="material.memo" style="width:100%;height:60px;" rows="" cols=""></textarea>
						</td>
						
					</tr>
					
				</table>
			</div>
			<div class="tabContent" id="checkReport_content" style="display:none;height:350px;">
				<table style="width:100%;" border="0">
					<tr>
						<td align="right">测试环境(温度):</td>
						<td align="left"><input type="text" name="material.temperature"/></td>
						<td align="right">报告编号:</td>
						<td align="left"><input type="text" id="reportID"/></td>
					</tr>
					<tr>
						<td align="right">测试环境(湿度):</td>
						<td align="left"><input type="text" name="material.environment"/></td>
						<td align="right">检验标准:</td>
						<td align="left"><input type="text" name="material.testStandard"/></td>
					</tr>
					<tr>
						<td colspan="4">
							<table style="width:100%;" border="0">
								<tr>
									<td>序号</td>
									<td>检验项目</td>
									<td>单位</td>
									<td>检验标准</td>
									<td>检验方法</td>
									<td>检验结果</td>
									<td>判定</td>
								</tr>
								<tr>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
								</tr>
							</table>
							
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div style="width:100%;height:100%;">
		<center>
			<input type="button" value="引原料送检单" onclick="showMessage()"/>
			<input type="submit" value="保存"/>
			<input type="button" value="请审"/>
			<input type="button" value="关闭"/>
		</center>
		</div>
		<div id="bg" style="background:#cccccc;filter:alpha(opacity=40);opacity:0.7;width:100%;position:absolute;left:0px;top:0px;
						display:none;z-index:0;"></div>
	</form>
</body>
</html>

 

你可能感兴趣的:(JavaScript,jquery,json,Ajax,css)