<html>
<head>
<title> Add and remove a row </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("");//The name of the newly added row is empty
$("tr:last > td > #address").val("");//The newly added line address is empty
});
$(".delOneRow").click(function() {
if ($("tr").length < 2) {
alert(" Keep at least one line !");
} else {
if (confirm(" Confirm the deletion ?")) {
$(this).parent().parent().remove();
}
}
});
});
</script>
</head>
<body>
<table border="1">
<tr>
<td> The name :</td>
<td><input type="text" id="name" name="name" />
</td>
<td> address :</td>
<td><input type="text" id="address" name="address" /></td>
<td><input type="button" class="delOneRow" value=" delete " /></td>
</tr>
</table>
<input type="button" id="addOneRow" value=" Add a line " />
</body>
</html>