<div class="codetitle"> <span><a style="CURSOR: pointer" data="18590" class="copybut" id="copybut18590" onclick="doCopy('code18590')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code18590"> <br> <br> <br><title>添加、删除一行</title> <br><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <br><script type="text/javascript" src="../js/jquery-1.9.1.js"></script> <br><script type="text/javascript"> <BR>$(function() { <BR>$("#addOneRow").click(function() { <BR>var tempTr = $("tr:first").clone(true); <BR>$("tr:last").after(tempTr); <BR>$("tr:last > td > #name").val("");//新添加行name为空 <BR>$("tr:last > td > #address").val("");//新添加行address为空 <BR>}); <BR>$(".delOneRow").click(function() { <BR>if ($("tr").length < 2) { <BR>alert("至少保留一行!"); <BR>} else { <BR>if (confirm("确认删除?")) { <BR>$(this).parent().parent().remove(); <BR>} <BR>} <BR>}); <BR>}); <BR></script> <br> <br><br> <br><table border="1"> <br><tr> <br><td>姓名:</td> <br><td> <input type="text" id="name" name="name"> <br> </td> <br><td>地址:</td> <br><td><input type="text" id="address" name="address"></td> <br><td><input type="button" class="delOneRow" value="删除"></td> <br> </tr> <br> </table> <br><input type="button" id="addOneRow" value="添加一行"> <br> <br><br> <br> </div>