<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><input type="button" class="delOneRow" value="刪除"> <br> </tr> <br> </table> <br><input type="button" id="addOneRow" value="新增一行"> <br> <br><br> <br> </div>