<script type="text/javascript" src="js/jquery1.7.js"></script>
<script type="text/javascript">
$(function () {
var show_count = 20;
var count = 1;
$("#btn_addtr").click(function () {
var length = $("#dynamicTable tbody tr").length;
if (length < show_count)
{
$("#tab11 tbody tr").clone().appendTo("#dynamicTable tbody");
changeIndex();
}
});
});
function changeIndex() {
var i = 1;
$("#dynamicTable tbody tr").each(function () {
$(this).find("input[name='NO']").val(i++);
});
}
function deltr(opp) {
var length = $("#dynamicTable tbody tr").length;
if (length <= 1) {
alert("至少保留一行");
} else {
$(opp).parent().parent().remove();
changeIndex();
}
}
</script>
<div style="width:720px;margin:20px auto;">
<table id="tab11" style="display: none">
<tbody>
<tr>
<td height="30" align="center">
<input type="text" name="NO" size="2" value="1" /></td>
<td align="center">
<input type="text" name="start_end_time" /></td>
<td align="center">
<input type="text" name="unit_department" /></td>
<td align="center">
<input type="text" name="post" /></td>
<td>
<input type="button" id="Button1" onClick="deltr(this)" value="删行">
</td>
</tr>
</tbody>
</table>
<input type="button" id="btn_addtr" value="增行">
<table id="dynamicTable" width="700" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td height="30" align="center" bgcolor="#CCCCCC">ID</td>
<td align="center" bgcolor="#CCCCCC">起止时间</td>
<td align="center" bgcolor="#CCCCCC">单位/部门</td>
<td align="center" bgcolor="#CCCCCC">职位</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td height="30" align="center">
<input type="text" name="NO" size="2" value="1" /></td>
<td align="center">
<input type="text" name="start_end_time" /></td>
<td align="center">
<input type="text" name="unit_department" /></td>
<td align="center">
<input type="text" name="post" /></td>
<td>
<input type="button" id="Button2" onClick="deltr(this)" value="删行">
</td>
</tr>
</tbody>
</table>
</div>