jquery動態(tài)添加刪除一行數(shù)據(jù)示例
更新時間:2014年06月12日 09:04:42 投稿:whsnow
這篇文章主要介紹了jquery如何動態(tài)添加刪除一行數(shù)據(jù),需要的朋友可以參考下
復制代碼 代碼如下:
<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>
相關(guān)文章
jquery導航制件jquery鼠標經(jīng)過變色效果示例
這篇文章主要介紹了jquery鼠標經(jīng)過變色效果代碼,大家參考使用吧2013-12-12
JavaScript實現(xiàn)向select下拉框中添加和刪除元素的方法
這篇文章主要介紹了JavaScript實現(xiàn)向select下拉框中添加和刪除元素的方法,涉及jQuery中append()與remove()方法動態(tài)操作表單元素的相關(guān)技巧,需要的朋友可以參考下2017-03-03
如何使用jQuery技術(shù)開發(fā)ios風格的頁面導航菜單
這篇文章主要介紹了如何使用jQuery技術(shù)開發(fā)ios風格的頁面導航菜單,需要的朋友可以參考下2015-07-07

