<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" bgcolor="#f7f7f7">
<table id="t1" width="100%" height="25" border="0" cellpadding="0" cellspacing="0" class="font_14">
<tr>
<td width="30"> </td>
<td width="130">文件地点:</td>
<td><!-- <input type="text" name="address" style="width:40% "/>
保管人:<input type="text" name="vindicator" id="vindicator" size="10"/>
<input type="hidden" name="vuserId" id="vuserId"/>
<input type="button" name="button" value=" 选择 " onclick="return showModalDpReturn('<%=request.getContextPath()%>/infpm/userMiddle.jsp?check=one','600','600',vindicator,vuserId);" class="input"/>-->
<input type="button" name="buttonadd" value="增加物理分发" class="input" onclick="addvindicator()" />
<!-- <input type="button" name="buttondel" value="删除物理分发" class="input" onclick="deletevindicator()" />-->
</td>
</tr>
</table></td>
</tr>
<tr>
<td height="1" bgcolor="#b5b5b5"></td>
</tr>
</table>
07年7月9日
这是前几天的东西了,现在整理出来:
(1)工作笔记中前面提到了动态的添加javascript的东西,现在要循环把动态添加的东西取出来,这是方法:
<script language="javascript">
var total = 0;
// 添加文件地址方法

function addvindicatorupdate(value1,value2,value3)...{
//alert(total);
var index = t1.rows.length;
//alert(index);
var oRow1=t1.insertRow(index);
var aRows=t1.rows;
var aCells1=oRow1.cells;
var oCell1_1=aRows(oRow1.rowIndex).insertCell(aCells1.length);
//oCell1_1.setAttribute("align","center");
var oCell1_2=aRows(oRow1.rowIndex).insertCell(aCells1.length);
//oCell1_2.setAttribute("align","center");
var oCell1_3=aRows(oRow1.rowIndex).insertCell(aCells1.length);
//oCell1_3.setAttribute("align","center");
var address = "address" + total;
var userId = "userId" + total;
var vindicator = "vindicator"+total;
var userName ="userName"+total;
total += 1;
//alert(total)
oCell1_1.innerHTML='';
oCell1_2.innerHTML='文件地点:';
oCell1_3.innerHTML='<input type="text" size="30" id="' + address + '" name="address" maxlenth="300" value="' + value1 + '" class="ddinput">'
+ '<input type="hidden" id="' + userId + '" name="vuserId" value="' + value2 + '">'+' '+'保管人:'
+'<input type="text" name="vindicator" id="'+vindicator+'" size="10" value="' + value3 + '">'
+ '<input type="button" name="button1" value=" 选择 " size="20" class="input" onclick="return showModalDpReturn('<%=request.getContextPath()%>/infpm/userMiddle.jsp?check=one','600','600',' + vindicator + ',' + userId + ')"/>';
}
// 添加文件地址方法

function addvindicator()...{
//alert(total);
var index = t1.rows.length;
//alert(index);
var oRow1=t1.insertRow(index);
var aRows=t1.rows;
var aCells1=oRow1.cells;
var oCell1_1=aRows(oRow1.rowIndex).insertCell(aCells1.length);
//oCell1_1.setAttribute("align","center");
var oCell1_2=aRows(oRow1.rowIndex).insertCell(aCells1.length);
//oCell1_2.setAttribute("align","center");
var oCell1_3=aRows(oRow1.rowIndex).insertCell(aCells1.length);
//oCell1_3.setAttribute("align","center");
var address = "address" + total;
var userId = "userId" + total;
var vindicator = "vindicator"+total;
var userName ="userName"+total;
total += 1;
//alert(total)
oCell1_1.innerHTML='';
oCell1_2.innerHTML='文件地点:';
oCell1_3.innerHTML='<input type="text" size="30" id="' + address + '" name="address" maxlenth="300" class="ddinput">'
+ '<input type="hidden" id="' + userId + '" name="vuserId">'+' '+'保管人:'
+'<input type="text" name="vindicator" id="'+vindicator+'" size="10">'
+ '<input type="button" name="button1" value=" 选择 " size="20" class="input" onclick="return showModalDpReturn('<%=request.getContextPath()%>/infpm/userMiddle.jsp?check=one','600','600',' + vindicator + ',' + userId + ')"/>';
}
//删除收件人

function deletevindicator()...{
var index = t1.rows.length;

if(index>1)...{
t1.deleteRow(index-1);
//t1.deleteRow(index-2);
//t1.deleteRow(index-3);
total = total - 1;
}
//alert(total);
}
</script>

<%
String value1="";
String value2="";
String value3="";
if(listaddress != null)

...{
for(int i=0;i<listaddress.size();i++)

...{
TfileAddress tfileAddress=(TfileAddress)listaddress.get(i);
value2 = tfileAddress.getTsysUserInf().getUserId().toString();
value1 = tfileAddress.getAddress();
value3 = tfileAddress.getTsysUserInf().getUserName().toString();
%>
<script>
addvindicatorupdate('<%=value1%>','<%=value2%>','<%=value3%>');
</script>
<%
}

}else...{
value1="";
value2="";
value3="";
%>
<script>
addvindicatorupdate('<%=value1%>','<%=value2%>','<%=value3%>');
</script>
<%
}
%>

value1 ,value2 ,value3,是添加的时候添加的数据,现在是修改页面,能保证修改.忘了把html页面部分补上了,下面是代码:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" bgcolor="#f7f7f7">
<table id="t1" width="100%" height="25" border="0" cellpadding="0" cellspacing="0" class="font_14">
<tr>
<td width="30"> </td>
<td width="130">文件地点:</td>
<td><!-- <input type="text" name="address" style="width:40% "/>
保管人:<input type="text" name="vindicator" id="vindicator" size="10"/>
<input type="hidden" name="vuserId" id="vuserId"/>
<input type="button" name="button" value=" 选择 " onclick="return showModalDpReturn('<%=request.getContextPath()%>/infpm/userMiddle.jsp?check=one','600','600',vindicator,vuserId);" class="input"/>-->
<input type="button" name="buttonadd" value="增加物理分发" class="input" onclick="addvindicator()" />
<!-- <input type="button" name="buttondel" value="删除物理分发" class="input" onclick="deletevindicator()" />-->
</td>
</tr>
</table></td>
</tr>
<tr>
<td height="1" bgcolor="#b5b5b5"></td>
</tr>
</table>
得了,顺便把判断循环动态添加的代码里面的判断不能为空的也加上吧,其实我根据需求做的是没有删除功能的,即使页面里动态的表格列出来不填也没关系,action里做了判断的,但是怕需求再次变化,只好加了删除的功能:

if(total >= 0)...{
document.getElementById("total").value = total;
var addresses = document.getElementsByName("address");
for(var i=0; i<addresses.length; i++)

...{
var name = "address" + i;
var addresslist = document.getElementsByName(name);
for(var k=0; k<addresslist.length; k++)

...{
if(addresslist[k].value=="")

...{
alert("文件地址不能为空!");
return false;
}
}
}
for(var i=0; i<addresses.length; i++)

...{
var name = "vindicator" + i;
var vindicatorlist = document.getElementsByName(name);
for(var j=0; j<vindicatorlist.length;j++)

...{
if(vindicatorlist[j].value=="")

...{
alert("保管人不能为空!");
return false;
}
}
}
}
恩,基本上全了,呵呵,睡觉喽!以后忘不了喽,记忆力又好使喽!