如下图所示
源代码如下:复制代码代码如下:DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN ' ' http://www .w3。L1-过渡时期。DTD ' html xmlns=' http://www .w3。org/1999/XHTML ' head title/title script type=' text/JavaScript '//进行数据验证函数validate form(){ var BookName list=document。getelementsbyname(' BookName ');var bookversionlist=document。getelementsbyname(' Version ');var booknumlist=文档。getelementsbyname(' BookNum ');for(var I=0;I bookname list . lentigi){ var bookname=bookname list[I].价值;var图书版本=图书版本列表[I].价值;var booknum=booknumlist[i].价值;if (bookname=='') { alert('第1 '行的图书名称不能为空!');返回false } if(book version==' '){ alert('第1 '行的图书版本不能为空!');返回false} if (booknum=='') { alert('第1 '行的图书数量不能为空!');返回false} if (isNaN(booknum)) { alert('第1 '行的图书数量输入的不正确!');返回false} }返回true } var RowNum=2;//添加一行函数AddRow(){ var my table=document。getelementbyidx _ x('我的表');var new tr=我的表。insert row(RowNum);var新td1=新tr。插入单元格(0);newTd1.setAttribute('align ',' center ');newtd1。innerhtml=' input type=' text ' name=' BookName ' style=' width :200 px ';var新td2=新tr。插入单元格(1);newTd2.setAttribute('align ',' center ');newtd2。innerhtml=' input type=' text ' name=' Version ' style=' width : 120 px '/';var新td3=新tr。插入单元格(2);newTd3.setAttribute('align ',' center ');newtd3。inner html=' input type=' text ' name=' BookNum ' style=' width : 56px '/';var新td4=新tr。插入单元格(3);newTd4.setAttribute('align ',' center ');newtd4。inner html=' input type=' text ' name=' book author ' style=' width : 70px '/';var新td5=新tr。插入单元格(4);newTd5.setAttribute('align ',' center ');newtd5。inner html=' input type=' text ' name=' BookPress ' style=' width : 102 px '/';rowNum} //删除最后一行函数DeleteRow(){ var my table=document。getelementbyidx _ x('我的表');if(RowNum 1){我的表。deleteRow(RowNum-1);rowNum-;} }/script/head body table id=' myTable '单元格间距=' 0px '单元格填充=' 2px '宽度=' 700 px ' tr TD align=' center ' style=' color : # 006699;' font-weight : bold;'图书名称/TD TD align=' center ' style=' color : # 006699;'字体粗细:加粗;'版本/TD TD align=' center ' style=' color : # 006699;' font-weight : bold;'数量(本)/TD TD align=' center ' style=' color : # 006699;'字体粗细:加粗;'图书作者/TD TD align=' center ' style=' color : # 006699;' font-weight : bold;'出版社/TD/tr TD对齐='中心'输入名称='BookName '类型=“文本”样式='宽度: 200 px '/TD TD TD align='中心'输入类型=“文本”名称='版本'样式='宽度: 120 px '/TD TD TD align='中心'输入类型=“文本”名称='BookNum '样式='宽度: 56px '/TD TD TD align='中心'输入类型=“文本”名称='BookAuthor '添加图书onclick=' AddRow()'/input type=' button ' value='删除图书onclick=' DeleteRow()'/input type=' button ' value='提交onclick=' ValidateForm()'//div/body/html