日期:2014-05-18  浏览次数:20950 次

jsp如何实现多行添加
要在jsp页面中单击添加按钮时动态添加一行,都添加完以后点击保存实现多行一起保存。请各位帮帮忙吧。。。。

------解决方案--------------------
没实现过,不过思路这样行不行:
动态添加一条记录,就动态生成一条sql语句,
点保存的时候,一块提交执行


------解决方案--------------------
动态添加可以用javascript实现。
你找一下insertRow(),insert Cell();
每一列都是一个数组,
获得他们的值就以后,保存还是难事吗?
------解决方案--------------------
页面放一个隐藏域放xml文本,输入部分用js动态增加,填入数据,js修改隐藏域的xml内容
------解决方案--------------------
<html>
<script language= "javascript ">
var rowid=1;
function $(id){
return document.getElementById(id);
}
function addRow(){
var _tab=$( "test ");
var _row=_tab.insertRow();
rowid+=1;
var _col1=_row.insertCell();
_col1.innerText=rowid;
_col1.align= "center ";
var _col2=_row.insertCell();
_col2.innerHTML= " <input type= 'text '> ";
_col2.align= "center ";
var _col3=_row.insertCell();
_col3.innerHTML= " <input type= 'text '> ";
_col3.align= "center ";
var _col4=_row.insertCell();
_col4.innerHTML= " <input type= 'text '> ";
_col4.align= "center ";

}
</script>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 增加行 </title>
</head>

<body>
<table>
<tr>
<td align= "center " valign= "top ">
<table width= "200 " border= "1 " align= "center ">
<tr>
<td> <input type= "button " name= "addBtn " value= "&nbsp;&nbsp;add&nbsp;&nbsp; " onClick= "addRow(); "> </td>
</tr>
<tr>
<td> <input type= "button " name= "addBtn " value= "delete "> </td>
</tr>
</table>
</td>
<td> <table id= "test " border= "1 ">
<tr>
<td> &nbsp; </td> <td align= "center "> ID </td> <td align= "center "> Name </td> <td align= "center "> Desc </td>
</tr>
<tr>
<td align= "center " width= "50 "> 1 </td>
<td> <input type= "text " name= "id " id= "testId "> </td>
<td> <input type= "text " name= "name " id= "testName "> </td>
<td> <input type= "text " name= "desc " id= "testDesc "> </td>
</tr>
</table> </td>
</tr>
</table>
</body>
</html>