表格的新增以及和删除一行数据(可以新增原有数据)

来源:互联网 发布:python使用turtle 编辑:程序博客网 时间:2024/06/05 19:44
<html> 
<head> 
<title>添加、删除一行</title> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.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" class="name" name="name" /> 
</td> 
<td>地址:</td> 
<td><input type="text" class="address" name="address" /></td> 
<td><input type="button" class="delOneRow" value="删除" /></td> 
</tr> 
</table> 
<input type="button" id="addOneRow" value="添加一行" /> 
</body> 


</html> 




阅读全文
0 0
原创粉丝点击