1. 程式人生 > >在一個table中動態添加一行或刪除一行

在一個table中動態添加一行或刪除一行

table 添加一行

	
	<table id="selected_user_table" width="100%" >
		<thead>
			<tr><th class="center" colspan="2"  style="background-color:#F2F2F2;height:20px;">已選擇</th></tr>
		</thead>
		<tbody id="select_user_td">
		</tbody>
	</table>
<script>
//添加一行
	var trHTML = "<tr id=‘tr_"+row.id+"‘><td width=‘10%‘><input  name=‘selected_user‘ type=‘checkbox‘/></td></tr>"
	if(isOder){
		$("#select_user_td tr:eq("+num+")").after(trHTML); 
	}else{
		$("#select_user_td").append(trHTML);
	}
	
	//刪除一行
	$("#tr_"+row.id).remove();//選中tr,然後刪除。
</script>


本文出自 “JianBo” 博客,轉載請與作者聯系!

在一個table中動態添加一行或刪除一行