復(fù)制代碼 代碼如下:
 
<html> 
<head> 
<title>添加、刪除一行</title> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
<script type="text/javascript" src="../js/jquery-1.9.1.js"></script> 
<script type="text/javascript"> 
$(function() { 
$("#addOneRow").click(function() { 
var tempTr = $("tr:first").clone(true); 
$("tr:last").after(tempTr); 
$("tr:last > td > #name").val("");//新添加行name為空 
$("tr:last > td > #address").val("");//新添加行address為空 
}); 
$(".delOneRow").click(function() { 
if ($("tr").length < 2) { 
alert("至少保留一行!"); 
} else { 
if (confirm("確認(rèn)刪除?")) { 
$(this).parent().parent().remove(); 
} 
} 
}); 
}); 
</script> 
</head> 
<body> 
<table> 
<tr> 
<td>姓名:</td> 
<td><input type="text" /> 
</td> 
<td>地址:</td> 
<td><input type="text" /></td> 
<td><input type="button" value="刪除" /></td> 
</tr> 
</table> 
<input type="button" value="添加一行" /> 
</body> 
</html> 
新聞熱點(diǎn)
疑難解答
圖片精選