<div class="codetitle"> <span><a style="CURSOR: pointer" data="49688" class="copybut" id="copybut49688" onclick="doCopy('code49688')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code49688"> <br> <br> <br> <br><title>table1.html</title> <br><br><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <br><meta http-equiv="description" content="this is my page"> <br><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <br><br><!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <br><script language="javascript" type="text/javascript"> <BR><!-- <BR>function test1(){ <BR>//判断插入的编号是否已经存在 <BR>for(var i=0;i<mytable.rows.length;i++){ <BR>var eachRow = mytable.rows[i]; <BR>if(eachRow.cells[0].innerText == no.value){ <BR>window.alert("编号已经存在!"); <BR>return ; <BR>} <BR>} <BR>//获取表单中的数据 <BR>var newTableRow = mytable.insertRow(mytable.rows.length); <BR>newTableRow.insertCell(0).innerText = no.value; <BR>newTableRow.insertCell(1).innerText = name1.value; <BR>newTableRow.insertCell(2).innerText = nickName.value; <BR>} <br><br>function test2(){ <BR>mytable.deleteRow(mytable.rows.length-1); <BR>} <BR>//--> <BR></script> <br> <br><br> <br><h1>英雄排行榜</h1> <br><table id="mytable" border="1"> <br><tr> <td>排名</td> <td>姓名</td> <td>外号</td> </tr> <br><tr> <td>1</td> <td>宋江</td> <td>及时雨</td> </tr> <br><tr> <td>2</td> <td>卢俊义</td> <td>玉麒麟</td> </tr> <br> </table> <br><h1>请输入新的好汉</h1> <br>编号<input id="no" type="text" value=""><br> <br>名字<input id="name1" type="text" value=""><br> <br>外号<input id="nickName" type="text" value=""><br> <br><input id="tianjia" type="button" value="添加" onclick="test1()"> <br><input type="button" value="删除最后一行" onclick="test2()"> <br> <br> <br> </div> <br><img src="http://files.jb51.net/file_images/article/201401/20140126155644.png?201402615572" alt="table对象中的insertRow与deleteRow使用示例_javascript技巧" >