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

如何在表格中自动增加行,并对输入的数据作判断
本人刚开始做jsp。
      现有一个问题,就是一个表格:
      第一行     显示表头
                      如         单号       名称     数量
      第二行     依次对应textbox     输入相应的数据,要对输入的数据作校验的
      可能会输如不确定的多行,所以需要自动增加行数的功能,请问怎么简捷快速的实现上述的功能!
      谢谢!

------解决方案--------------------
可以增加个按钮
事件触发js实现table的行增加
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<style type= "text/css ">
<!--
.list_over
{
background: #8080ff;font: italic medium; color: #ffff00;
}
.list_bg1
{
background: #80ff00;
}
.list_bg2
{
background: #FF0000;
}
-->
</style>

<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>

<script language= "javascript ">

function addRow(){
var lastRow=filetb.rows[filetb.rows.length-1];
alert(lastRow.innerHTML);
var lr=filetb.insertRow(filetb.rows.length);
lr.innerHTML=lastRow.innerHTML;
}
/*
动态添加table.将table中的text的值存入另一text中,在后台得到另一text的值
注意:1。OnChanged将“text的值存入另一text中”。如果此事件写入后台代码,将得不到。因为被postback掉了。
故先存,再运行后台代码。
2。在html中有一table,名字为filetb。
如果需要动态修改,在table里添加literal.text.
*/
var allCount;
allCount=0;
function addAttachment() {
allCount++;
var Num,p,myrow,indexnewrow,c1,c2,c3,c4;
var rown=filetb.rows.length;
myrow=filetb.insertRow(rown);
myrow.id= "tdt "+allCount;
myrow.name= "tdt "+allCount;
var cName= "list_bg2 ";
if(rown%2==0){
cName= "list_bg1 ";
}
myrow.className=cName;
myrow.onmouseover=function(){this.className= "list_over ";};
myrow.onmouseout=function(){this.className=cName;};
c1=myrow.insertCell();
c1.width= "100 ";
c1.align= "right ";
c1.innerHTML= " <p align=right> 代码 " + (allCount) + ": ";

c2=myrow.insertCell();
c2.align= "left ";
c2.innerHTML= " <INPUT type= 'text ' onchange= 'return GetValue() ' style= 'width:150 ' class=t1 name=txtCode1 "+(allCount)+ " MaxLength= '50 ' value=\ "a "+allCount+ "\ "> ";
c3=myrow.insertCell();
c3.align= "center ";
c3.innerHTML= " <a href= 'javascript:setValue( " + allCount + "); '> 取值 </a> &nbsp;&nbsp;&nbsp; <a href= 'javascript:deleteRow( " + allCount + "); '> 删除 </a> ";
c4=myrow.insertCell();
c4.align= "left ";
c4.innerHTML= " <INPUT type= 'text ' onchange= 'return GetValue() ' style= 'width:150 ' class=t1 name=txtCode2 "+(allCount)+ " MaxLength= '50 ' value=\ "b "+allCount+ "\ "> ";
}
function setValue(rid){
for(i=0;i <filetb.rows.length;i++){
var curRow=filetb.rows[i];