2009-07-02 22 views
0

在以下代碼中,$ j是jquery對象。我想知道爲什麼我可以追加到tbody標籤上,但是我無法通過選擇器中的tr標籤:tr tbody或tr。我如何正確追加到表格行?感謝您的幫助。我該如何去追加jQuery中的每個函數的表格行

var $this = $j('<table><thead></thead><tbody><tr></tr></tbody></table>'); 
$j.each(settings.columns, function(i, val) { 
     $j('<td></td>').appendTo($this.children('tbody tr')); 
     // Doesnt work with tr selector either, but works with tbody 
     // More code 
} 

回答

3

children只發現眼前的孩子(因此爲什麼<tbody>作品),你想find否則:

$j('<td></td>').appendTo($this.find('tbody tr')); 

你也可以使用$this作爲查詢的context

$j('<td></td>').appendTo($j('tbody tr', $this)); 
+0

沒錯我在找什麼,謝謝。 – user127706 2009-07-02 21:29:26