代码如下:
<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("确认删除?")) {
$(this).parent().parent().remove();
}
}
});
});
</script>
</head>
<body>
<table border="1">
<tr>
<td>姓名:</td>
<td><input type="text" id="name" name="name" />
</td>
<td>地址:</td>
<td><input type="text" id="address" name="address" /></td>
<td><input type="button" class="delonerow" value="删除" /></td>
</tr>
</table>
<input type="button" id="addonerow" value="添加一行" />
</body>
</html>
如对本文有疑问, 点击进行留言回复!!
【JavaScript笔记(一)】万丈高楼平地起 - 基本概念篇
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
vert实践五——Json?Protocol Buffer?FlatBuffers?
[基于tensorflow的人脸检测] 基于神经网络的人脸检测8——验证训练好的神经网络
网友评论