贴出代码:
<HTML>
<SCRIPT LANGUAGE="JScript">
function numberCells()
{
}function tb_addnew()
{
var ls_t=document.all("mytable")
maxcell=ls_t.rows(0).cells.length;
mynewrow = ls_t.insertRow();
mynewcell=mynewrow.insertCell();
mynewcell.innerText=document.all.mytable.rows.length -1
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.khyhmc2.value;
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.yhzh2.value;
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.yhzh2.value;
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.khrq2.value;
}function tb_delete()
{
var ls_t=document.all("mytable");ls_t.deleteRow() ;
}</SCRIPT>
<BODY onload="numberCells()">
<form name="form1" method="post" action="1.jsp">
<table id=mytable border=1 width="669" height="27">
<tr>
<th width="40" height="24">序号</th>
<th width="259" height="24">银行名称 </th>
<th width="167" height="24">银行帐号</th>
<th width="55" height="24">货币 </th>
<th width="114" height="24">是否缴税帐号</th>
</tr>
</table>
<table bordercolordark=#ccccff width="500" bordercolorlight=#000000 border=0>
<tbody>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <a href="#" style="COLOR: #000066; TEXT-DECORATION: none" tabindex=-1 title=由填表单位据实填写本单位开设的所有银行帐号。 >
<font color="#ff0000">*</font> 开户银行名称: </a> </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=khyhmc2>
</td>
</tr>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
银行帐号: </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=yhzh2>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
货币: </td>
<td width="65%">
<select name=select>
</select>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
开户日期: </td>
<td width="65%">
<input maxlength=10 name=khrq2
>
(格式:年-月-日,如1992-01-25) </td>
</tr>
</tbody>
</table>
<input type=button value="新增" onClick="tb_addnew()" name="button2">
<input type=button value="删除" onClick="tb_delete()" name="button" >
</form>
<p> </p>
<p> </p>
</BODY>
</HTML>
<HTML>
<SCRIPT LANGUAGE="JScript">
function numberCells()
{
}function tb_addnew()
{
var ls_t=document.all("mytable")
maxcell=ls_t.rows(0).cells.length;
mynewrow = ls_t.insertRow();
mynewcell=mynewrow.insertCell();
mynewcell.innerText=document.all.mytable.rows.length -1
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.khyhmc2.value;
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.yhzh2.value;
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.yhzh2.value;
mynewcell=mynewrow.insertCell();
mynewcell.innerText=form1.khrq2.value;
}function tb_delete()
{
var ls_t=document.all("mytable");ls_t.deleteRow() ;
}</SCRIPT>
<BODY onload="numberCells()">
<form name="form1" method="post" action="1.jsp">
<table id=mytable border=1 width="669" height="27">
<tr>
<th width="40" height="24">序号</th>
<th width="259" height="24">银行名称 </th>
<th width="167" height="24">银行帐号</th>
<th width="55" height="24">货币 </th>
<th width="114" height="24">是否缴税帐号</th>
</tr>
</table>
<table bordercolordark=#ccccff width="500" bordercolorlight=#000000 border=0>
<tbody>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <a href="#" style="COLOR: #000066; TEXT-DECORATION: none" tabindex=-1 title=由填表单位据实填写本单位开设的所有银行帐号。 >
<font color="#ff0000">*</font> 开户银行名称: </a> </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=khyhmc2>
</td>
</tr>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
银行帐号: </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=yhzh2>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
货币: </td>
<td width="65%">
<select name=select>
</select>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
开户日期: </td>
<td width="65%">
<input maxlength=10 name=khrq2
>
(格式:年-月-日,如1992-01-25) </td>
</tr>
</tbody>
</table>
<input type=button value="新增" onClick="tb_addnew()" name="button2">
<input type=button value="删除" onClick="tb_delete()" name="button" >
</form>
<p> </p>
<p> </p>
</BODY>
</HTML>
不行吗?
你的意思是,在表格动态增加一行时,将CELL设成文字域吗???
mynewrow = ls_t.insertRow();
String data = data + "<input type='text' size=10 name=" + inter
+ "url" + i + inter + "'><br>";
有两个问题:
1、表格的每一行记录由多个变量组成,语句怎么写能在新增一行的第一列放下一个文字域,NAME我可以指定为YHMC;第二列又放下一个文字域,NAME我可以指定YHZH。
2、我怎么把输入FORM中的文字域的值放进去呢?难道是用<INPUT TYPE ="TEXT" SIZE = 10 NAME ='' VALUE = '' >
///////////////////////
<HTML>
<script language=javascript>
function addLine()
{
elm = thead1.lastChild.cloneNode(true)
elm.style.display="block";
tbody1.insertBefore(elm);
tbody1.rows[tbody1.rows.length-1].cells[1].firstChild.value=tbody1.rows.length;
}
function deleteLine()
{
for (var i=tbody1.children.length-1; i>=0 ; i-- )
if (tbody1.children[i].firstChild.firstChild.checked)
tbody1.deleteRow(i);
for(var i=0;i<tbody1.children.length;i++)
tbody1.rows[i].cells[1].firstChild.value=i+1;
}
</script>
<BODY >
<form name="form1" method="post" action="1.jsp">
<table id=mytable border=1 width="669" height="27">
<thead id="thead1">
<tr>
<th width="40" height="24">选择</th>
<th width="40" height="24">序号</th>
<th width="259" height="24">银行名称 </th>
<th width="167" height="24">银行帐号</th>
<th width="55" height="24">货币 </th>
<th width="114" height="24">是否缴税帐号</th>
</tr>
<tr style="display:none">
<td width="40" height="24"><input type=checkbox name=checked></td>
<td width="40" height="24"><input size=4 name=num readonly></td>
<td width="259" height="24"><input size=10 name=bankname></td>
<td width="167" height="24"><input size=10 name=bankid></td>
<td width="55" height="24"><input size=10 name=currency </td>
<td width="114" height="24"><input size=10 name=istax></td>
</tr>
</thead>
<tbody id="tbody1">
<tr>
<td width="40" height="24"><input type=checkbox name=checked></td>
<td width="40" height="24"><input size=4 name=num value=1 readonly></td>
<td width="259" height="24"><input size=10 name=bankname></td>
<td width="167" height="24"><input size=10 name=bankid></td>
<td width="55" height="24"><input size=10 name=currency </td>
<td width="114" height="24"><input size=10 name=istax></td>
</tr>
</tbody>
</table>
<table bordercolordark=#ccccff width="500" bordercolorlight=#000000 border=0>
<tbody>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <a href="#" style="COLOR: #000066; TEXT-DECORATION: none" tabindex=-1 title=由填表单位据实填写本单位开设的所有银行帐号。 >
<font color="#ff0000">*</font> 开户银行名称: </a> </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=khyhmc2>
</td>
</tr>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
银行帐号: </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=yhzh2>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
货币: </td>
<td width="65%">
<select name=select>
</select>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
开户日期: </td>
<td width="65%">
<input maxlength=10 name=khrq2
>
(格式:年-月-日,如1992-01-25) </td>
</tr>
</tbody>
</table>
<input type=button value="新增" onClick="addLine()" name="button2">
<input type=button value="删除" onClick="deleteLine()" name="button" >
</form>
<p> </p>
<p> </p>
</BODY>
</HTML>///////////////////////////////////////////////
在接受页面用String[] request.getParameterValues()可获得一列表单值,其结果是字符串数组,如下:
String[] num=request.getParameterValues("num");
String[] bankname=request.getParameterValues("bankname");
for(int i=1;i<num.length;i++)//注意是从1开始,因为有一行隐藏的输入框
out.println(num[i]+" "+bankname[i]+"<br");//根据需要处理
<HTML>
<script language=javascript>
function addLine()
{
elm = thead1.lastChild.cloneNode(true)
elm.style.display="block";
tbody1.insertBefore(elm);
tbody1.rows[tbody1.rows.length-1].cells[1].firstChild.value=tbody1.rows.length;
tbody1.rows[tbody1.rows.length-1].cells[2].firstChild.value=form1.khyhmc2.value;
tbody1.rows[tbody1.rows.length-1].cells[3].firstChild.value=form1.yhzh2.value;
tbody1.rows[tbody1.rows.length-1].cells[4].firstChild.value=form1.yhzh2.value;
tbody1.rows[tbody1.rows.length-1].cells[5].firstChild.value=form1.yhzh2.value;
}
function deleteLine()
{
for (var i=tbody1.children.length-1; i>=0 ; i-- )
if (tbody1.children[i].firstChild.firstChild.checked)
tbody1.deleteRow(i);
for(var i=0;i<tbody1.children.length;i++)
tbody1.rows[i].cells[1].firstChild.value=i+1;
}
</script>
<BODY >
<form name="form1" method="get" action="add2.jsp">
<table id=mytable border=1 width="616" height="27">
<thead id="thead1">
<tr>
<th width="33" height="24">选择</th>
<th width="37" height="24">序号</th>
<th width="139" height="24">银行名称 </th>
<th width="191" height="24">银行帐号</th>
<th width="75" height="24">货币 </th>
<th width="154" height="24">是否缴税帐号</th>
</tr>
<tr style="display:none">
<td width="33" height="13">
<input type=checkbox name=checked>
</td>
<td width="37" height="13">
<input size=4 name=num readonly>
</td>
<td width="139" height="13">
<input size=20 name=bankname>
</td>
<td width="191" height="13">
<input size=30 name=bankid>
</td>
<td width="75" height="13">
<input size=10 name=currency >
</td>
<td width="154" height="13">
<input size=10 name=istax>
</td>
</tr>
</thead>
</table>
<font face="宋体"></font>
<table id=mytable border=1 width="616" height="27">
<tbody id="tbody1">
<tr>
<td width="33" height="24">
<input type=checkbox name=checked>
</td>
<td width="37" height="24"><font face="宋体"></font>
<input size=4 name=num value=1 readonly>
</td>
<td width="139" height="24">
<input size=20 name=bankname>
</td>
<td width="191" height="24">
<input size=30 name=bankid>
</td>
<td width="75" height="24">
<input size=10 name=currency >
</td>
<td width="154" height="24">
<input size=10 name=istax>
</td>
</tr>
</tbody>
</table>
<table bordercolordark=#ccccff width="500" bordercolorlight=#000000 border=0>
<tbody>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <a href="#" style="COLOR: #000066; TEXT-DECORATION: none" tabindex=-1 title=由填表单位据实填写本单位开设的所有银行帐号。 >
<font color="#ff0000">*</font> 开户银行名称: </a> </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=khyhmc2>
</td>
</tr>
<tr>
<td width="35%" height=31 align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
银行帐号: </td>
<td width="65%" height=31>
<input maxlength=50 size=30 name=yhzh2>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
货币: </td>
<td width="65%">
<select name=select>
</select>
</td>
</tr>
<tr>
<td width="35%" align="right" bgcolor="#e8eeff"> <font color="#ff0000">*</font>
开户日期: </td>
<td width="65%">
<input maxlength=10 name=khrq2
>
(格式:年-月-日,如1992-01-25) </td>
</tr>
</tbody>
</table>
<input type=button value="新增" onClick="addLine()" name="button2">
<input type=button value="删除" onClick="deleteLine()" name="button" >
<input type="submit" name="Submit" value="提交">
</form>
<p> </p>
<p> </p>
</BODY>
</HTML>我测出字符串数组的长度是正确的,但是值没有取够,只取出了第一行的记录
。我经验不够,您费心了。
接受页面:
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<title>
add2
</title>
</head>
<jsp:useBean id="add2BeanId" scope="session" class="web_tax.add2Bean" />
<jsp:setProperty name="add2BeanId" property="*" />
<%
String num[]=request.getParameterValues("num");
String bankname[]=request.getParameterValues("bankname");
for(int i=1;i<num.length;i++)//注意是从1开始,因为有一行隐藏的输入框
{
out.println(num[i]+" "+bankname[i]+"<br");//根据需要处理
}
%>
<body>
</body>
</html>
你直接把我的文件拷下去看一看效果就知道了
另外,我的输出时少了一个>号,正确如下
out.println(num[i]+" "+bankname[i]+"<br>")
看了你上面的代码(楼顶),很好!有一个BUG ,在点击“删除”时,会将表格上面的文字(序号,银行名称 )删除,能不能修改一下我想请教一个问题,怎样在点击“增加”的同时完成将数据写入数据库,点击“删除”的同时从数据库中删除数据,并且,表格视图上也作相应的变化呢?能不能在你这个例子上修改一个,EMAIL给我,太感谢了!!!顺便谢谢你以前回答我的问题,我的EMAIL:[email protected]