如下图所示: 源代码如下: 复制代码 代码如下: <BR>//进行数据验证 <BR>function ValidateForm() { <BR>var booknamelist = document.getElementsByName("BookName"); <BR>var bookversionlist = document.getElementsByName("Version"); <BR>var booknumlist = document.getElementsByName("BookNum"); <BR>for (var i = 0; i < booknamelist.length; i++) { <BR>var bookname = booknamelist[i].value; <BR>var bookversion = bookversionlist[i].value; <BR>var booknum = booknumlist[i].value; <BR>if (bookname == "") { <BR>alert("第" + (i + 1) + "行的图书名称不能为空!"); <BR>return false; <BR>} <BR>if (bookversion == "") { <BR>alert("第" + (i + 1) + "行的图书版本不能为空!"); <BR>return false; <BR>} <BR>if (booknum == "") { <BR>alert("第" + (i + 1) + "行的图书数量不能为空!"); <BR>return false; <BR>} <BR>if (isNaN(booknum)) { <BR>alert("第" + (i + 1) + "行的图书数量输入的不正确!"); <BR>return false; <BR>} <BR>} <BR>return true; <BR>} <BR>var rowNum = 2; <BR>//添加一行 <BR>function AddRow() { <BR>var myTable = document.getElementByIdx_x("myTable"); <BR>var newTr = myTable.insertRow(rowNum); <BR>var newTd1 = newTr.insertCell(0); <BR>newTd1.setAttribute("align", "center"); <BR>newTd1.innerHTML = '<input type="text" name="BookName" style="width:200px">'; <BR>var newTd2 = newTr.insertCell(1); <BR>newTd2.setAttribute("align", "center"); <BR>newTd2.innerHTML = '<input type="text" name="Version" style="width: 120px" />'; <BR>var newTd3 = newTr.insertCell(2); <BR>newTd3.setAttribute("align", "center"); <BR>newTd3.innerHTML = '<input type="text" name="BookNum" style="width: 56px" />'; <BR>var newTd4 = newTr.insertCell(3); <BR>newTd4.setAttribute("align", "center"); <BR>newTd4.innerHTML = '<input type="text" name="BookAuthor" style="width: 70px" />'; <BR>var newTd5 = newTr.insertCell(4); <BR>newTd5.setAttribute("align", "center"); <BR>newTd5.innerHTML = '<input type="text" name="BookPress" style="width: 102px" />'; <BR>rowNum++; <BR>} <BR>//删除最后一行 <BR>function DeleteRow() { <BR>var myTable = document.getElementByIdx_x("myTable"); <BR>if (rowNum > 1) { <BR>myTable.deleteRow(rowNum-1); <BR>rowNum--; <BR>} <BR>} <BR> 图书名称 版 本 数量(本) 图书作者 出版社 onclick="DeleteRow()" />