jquery实现tr在table中增加删除

<script>

function addtable(){

$("#detail-table tbody").append("<tr><td><input type='text' name='detail_name[]' class='detail_name' value=''></td><td><input type='text' name='detail_num[]' class='detail_num' value=''></td><td><input type='text' name='detail_price[]' class='detail_price' value=''></td><td><input type='text' name='detail_remark[]' class='detail_remark' value=''></td><td onClick='addtable()'>+</td> <td onClick='reducetable(this)' class='del'>-</td></tr>");
}
function reducetable(obj){
$(obj).parent('tr').remove();
}
</script>

html:

 

<div class="slider-left">
<form action="admin_allot.php" name="myform" id="myform" method="POST" >
<input type="hidden" name="planid" id="planid" value="<{$planid}>">
<div class="form-group">
<h6 style="text-align:center;">调拨详情</h6>
<table id="detail-table" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>物资名称</th>
<th>调拨数量</th>
<th>预计单价(元)</th>
<th>备注</th>
<th>添加</th>
<th>删减</th>
</tr>
<thead>
<tbody>
<tr>
<td><input type="text" name="detail_name[]" class="detail_name" value=""/></td>
<td><input type="text" name="detail_num[]" class="detail_num" value=""/></td>
<td><input type="text" name="detail_price[]" class="detail_price" value="" /></td>
<td><input type="text" name="detail_remark[]" class="detail_remark" value="" "/></td>
<td onClick="addtable()">+</td>
<td onClick="reducetable(this)" class="del">-</td>
</tr>
</tbody>
</table>
</div>

 

 

posted on 2017-05-26 16:02  落花风总惹人烦忧  阅读(306)  评论(0)    收藏  举报

导航