任意行數的數據輸入表格

初始界面:


點擊添加就等添加一行輸入框!

添加幾行後的界面:



頁面代碼:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
 
    <title>My JSP 'insnewequipment.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
	<style type="text/css">
		table{
			table-layout:fixed;
   		 	empty-cells:show; 
    		border-collapse: collapse;
    		margin:0 auto;
    		background-color:#e8f3fd;
		} 
		td{
			text-align:center;
			border:1px solid #cad9ea;
		}
		a:link { 
			text-decoration: none; 
			color: blue; 
			line-hight:18px;
		} 
	</style>
	<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
	<script language="javascript" type="text/javascript">
	function findObj(theObj, theDoc){ 
		var p, i, foundObj; 
		if(!theDoc) theDoc = document; 
		if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
			theDoc = parent.frames[theObj.substring(p+1)].document;    
			theObj = theObj.substring(0,p); 
		} 
		if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; 
		for (i=0; !foundObj && i < theDoc.forms.length; i++){     
			foundObj = theDoc.forms[i][theObj]; 
		}
		for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++){     
			foundObj = findObj(theObj,theDoc.layers[i].document); 
		}
		if(!foundObj && document.getElementById){ 
			foundObj = document.getElementById(theObj);    
			return foundObj;
		}
	}
	//添加一個參與人填寫行
	function AddSignRow(){ 
		//讀取最後一行的行號,存放在txtTRLastIndex文本框中 
		var txtTRLastIndex = findObj("txtTRLastIndex",document);
		var rowID = parseInt(txtTRLastIndex.value);
		if(rowID>12){
			alert("每次最多添加12個,請保存後繼續添加!");
		}else{
	
		var signFrame = findObj("SignFrame",document);
		//添加行
		var newTR = signFrame.insertRow(signFrame.rows.length);
		newTR.id = "SignItem" + rowID;
	
		//添加列:設備編號
		var newEquipmentIdTD=newTR.insertCell(0);
		//添加列內容
		newEquipmentIdTD.innerHTML = "<input name='equipmentId" + rowID + "' id='equipmentId" + rowID + "' type='text' size='10' />";
		
		//添加列:設備種類
		var newEquipmentCategoryIdTD=newTR.insertCell(1);
		//添加列內容
		newEquipmentCategoryIdTD.innerHTML = "<select name='equipmentCategoryId" + rowID + "' id='equipmentCategoryId" + rowID + "' style='width:92px;'><option value='0'>請選擇</option><option value='1'>POS機</option><option value='2'>PSAM卡</option><option value='3'>ISAM卡</option><option value='4'>採集器</option></select>";
		
		//添加列:出廠編號
		var newProductionIdTD=newTR.insertCell(2);
		//添加列內容
		newProductionIdTD.innerHTML = "<input name='productionId" + rowID + "' id='productionId" + rowID + "' type='text' size='10' />";
		
		//添加列:設備類型
		var newEquipmentTypeIdTD=newTR.insertCell(3);
		//添加列內容
		newEquipmentTypeIdTD.innerHTML = "<select name='equipmentTypeId" + rowID + "' id='equipmentTypeId" + rowID + "' style='width:92px;'><option value='0'>請選擇</option><option value='1'>普通消費POS</option><option value='2'>公交車載POS</option></select>";
		
		//添加列:設備型號
		var newEquipmentModelTD=newTR.insertCell(4);
		//添加列內容
		newEquipmentModelTD.innerHTML = "<input name='equipmentModel" + rowID + "' id='equipmentModel" + rowID + "' type='text' size='10' />";
		
		//添加列:備註
		var newNotesTD=newTR.insertCell(5);
		//添加列內容
		newNotesTD.innerHTML = "<input name='notes" +rowID+"'id'=notes"+rowID+"'type='text' size='18' />";
		//添加列:刪除按鈕
		var newDeleteTD=newTR.insertCell(6);
		//添加列內容
		newDeleteTD.innerHTML = "<div align='center' style='width:100px'><a href='javascript:;' οnclick=\"DeleteSignRow('SignItem" + rowID + "')\">刪除</a></div>";
		
		//將行號推進下一行
		txtTRLastIndex.value = (rowID + 1).toString() ;
		}
	}
	
	
	//刪除指定行
	function DeleteSignRow(rowid){
		var signFrame = findObj("SignFrame",document);
		var signItem = findObj(rowid,document);
	
		//獲取將要刪除的行的Index
		var rowIndex = signItem.rowIndex;
	
		//刪除指定Index的行
		signFrame.deleteRow(rowIndex);
	
	}
	
	//清空列表
	function ClearAllSign(){
		if(confirm('確定要清空所有嗎?')){
			var signFrame = findObj("SignFrame",document);
			var rowscount = signFrame.rows.length;
	
			//循環刪除行,從最後一行往前刪除
			for(var i=rowscount - 1;i > 0; i--){
	   		signFrame.deleteRow(i);
			}
	
			//重置最後行號爲1
			var txtTRLastIndex = findObj("txtTRLastIndex",document);
			txtTRLastIndex.value = "1";
	
			//預添加一行
			AddSignRow();
		}
	}
	
	
	</script>
	

  </head>
  
  <body>
  	<div style="text-align:center;">新增設備入庫<hr/></div>
  	
  	<table style="margin:0 auto;">
  		<tr>
  			<td style="width:100px;">設備廠商</td>
  			<td style="width:200px; text-align:left;" colspan=3>
  				<select name="supplierId" id="supplierId" style="width:200px;">
    				<option value="1111">CMCC-EDU</option>
        			<option value="2222">ChinaNet</option>
        			<option value="3333">ChinaUnicom</option>
        			<option value="4444">SDIPT</option>
    			</select><span style="color:red;">*</span>
  			</td>
  		</tr>
  		<tr>
  			<td>經辦人</td>
  			<td style="width:209px; text-align:left;"><input type="text" name="buyPerson" id="buyPerson" /><span style="color:red;">*</span></td>
  			<td style="width:100px;">日期</td>
  			<td style="width:350px; text-align:left;"><input class="Wdate" type="text" name="purchaseDate" id="purchaseDate" onClick="WdatePicker()"></td>
  		</tr>
  	</table>
  	
  	<table style="margin:0 auto; margin-top:1px;" id="SignFrame">
  		<tr id="trHeader">
  			<td style="width:100px;">設備編號</td>
  			<td style="width:100px;">設備種類</td>
  			<td style="width:100px;">出廠編號</td>
  			<td style="width:100px;">設備類型</td>
  			<td style="width:100px;">設備型號</td>
  			<td style="width:150px;">備註</td>
  			<td style="width:100px;">操作</td>
  		</tr>
  	</table>
  	
  	<table>
  		<tr>
  			<td style="width:665px;"></td>
  			<td style="width:100px;"><a href="javascript:;" οnclick="AddSignRow()">添加</a></td>
  		</tr>
  		<tr>
  			<td colspan=2>
  				<input type="button" name="Submit1" value="保存" οnclick="AddEquipment()">
  				<input type="button" name="Submit2" value="清空" οnclick="ClearAllSign()" />
  				<input name='txtTRLastIndex' type='hidden' id='txtTRLastIndex' value="1" />
  			</td>
  		</tr>
  	</table>
  	
  </body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章