克隆比對的dom元素并且選中這些克隆的副本。
在想把dom文檔中元素的副本添加到其他位置時這個函數非常有用。
要做到動态添加表格,并且添加後修改表格中每一列的值,非常友善
js代碼
$(function(){
var templatetr = $("#templaterow").clone();
var firsttd = templatetr.find("td:eq(0)");
var secondtd = templatetr.find("td:eq(1)");
firsttd.html("helloworld")
alert(secondtd.html());
});
html代碼
<table id="tableid" width="100%" border="0" cellspacing="0" cellpadding="0" class="common-table" height="10">
<tr id="templaterow" style="display:none;">
<td width="15%">源系統</td>
<td width="15%">方向</td>
<td width="15%">目标系統</td>
<td width="55%">封包資訊</td>
</tr>
</table>
用這個可以實作表格的複制并且動态的添加表格中的行。