2012-08-14 86 views
1

我使用下面的jQuery代碼將追加到我的表:jQuery的追加到表TR

 $("tbody#order_details").append('<tr>...</tr><tr>...</tr>'); 
     $("tbody#order_details").append('<tr>...</tr><tr>...</tr>'); 

然而,當它執行它放置<tr>...</tr><tr>...</tr>在頁面的頂部,而不是下面在當前<tbody id="order_details">開始。

表的代碼是這樣的:

 <table border="1" cellspacing="0" cellpadding="0" id="OrdersTable" 
      style="border: 1px solid black; margin-top: 0px;"> 
     <tbody> 
     <tr> 
      <th>Account Number</th> 
      <td colspan="3">99996</td> 
      <th>Email</th> 
      <td colspan="5"><asp:Label ID="billing_email" runat="server" Text="Label"></asp:Label></td> 
      </tr> 
     <tr> 
     etc etc.... 
     </tbody> 
      <tbody id="order_details"> 
       <!-- Start looping the orders here --> 

      </tbody> 
     </table> 

什麼我忘了整理爲它那兩行添加<tbody id="order_details">後?

+0

怎麼樣TD? – mplungjan 2012-08-14 14:48:27

+3

您的標記無效。 – undefined 2012-08-14 14:49:16

+2

爲什麼你有一個關閉'thead'標籤的開放'tbody'標籤 – 2012-08-14 14:49:26

回答

1

只是改變這個網站這樣:

 <table border="1" cellspacing="0" cellpadding="0" id="OrdersTable" style="border: 1px solid black; margin-top: 0px;"> 
     <thead> 
     <tr> 
      <th>Account Number</th> 
      <th colspan="3">99996</th> 
      <th>Email</th> 
      <th colspan="5"><asp:Label ID="billing_email" runat="server" Text="Label"></asp:Label></th> 
     </tr> 
     etc etc.... 
     </thead> 
     <tbody id="order_details"> 
      <!-- Start looping the orders here --> 

     </tbody> 
     </table> 

我想這是因爲HTML標記的, 我希望這會有所幫助。

+0

'​​'仍在''內。他也不能在他的「」上追加一個「」而沒有「​​」。 – Ohgodwhy 2012-08-14 14:53:49

+0

ohh狗屎對不起,讓我更新,謝謝你 – 2012-08-14 14:54:36

+0

還有一個未封閉的標籤在頭上,colspan屬性的th元素和看起來像頭部的數據。我認爲存在更大的問題,而不僅僅是一個小標記錯誤。 – jasonlfunk 2012-08-14 14:56:29

1

你必須在TD中寫下「...」。應該 ... 。

爲了獲得更好的性能,請使用#order_details而不是tbody#order_details。由於ID是唯一的,jQuery將始終找到正確的元素,而無需指定標記名稱

1

試試這個::

$("tbody#order_details").append('<tr><td>...</td></tr><tr><td>...</td></tr>'); 
+0

這導致它在表格的底部。 – StealthRT 2012-08-14 15:00:05