Jquery调整表以将tds添加到一行?

问题描述 投票:0回答:2

我有一张看起来如下的桌子......

<table width="100%" >   
  <tr class="odd">
    <td><img src="icn_pdf.gif"></td>
    <td><strong>Application Form</strong></td>
    <td><a href="/Form.pdf" class="smd"></a></td>
  </tr>
 <tr>
    <td><img src="icn_pdf.gif"></td>
    <td><strong>Application Form</strong></td>
    <td><a href="/Form.pdf" class="smd"></a></td>
  </tr> 
  <tr class="odd">
    <td><img src="icn_pdf.gif"></td>
    <td><strong>Application Form</strong></td>
    <td><a href="/Form.pdf" class="smd"></a></td>
  </tr> 
 <tr>
    <td><img src="icn_pdf.gif"></td>
    <td><strong>Application Form</strong></td>
    <td><a href="/Form.pdf" class="smd"></a></td>
  </tr>
</tbody></table>

目前,您可以在每行上看到每个“文档”。我想通过jQuery做的是循环并且有两行包含两个文件。那么每行6个tds?

jquery html-table rows
2个回答
2
投票

请检查这个小提琴链接。 http://jsfiddle.net/MgSsy/

$(function() {
    $('table tr:odd').each(function() {
        $this = $(this);
        $this.prev().append(($this.html()));
        $this.remove();
    });
});​

我想这就是你想要的。

根据我对您的代码的理解,我这样做了。


0
投票
<script>
$(function() {

   $('#btn').on('click', fuction(){
     //adding to the first row
     $('#table tbody').prepend('<tr><td>...</td>...</tr>');

     //adding to the end
     $('#table tbody').append('<tr><td>...</td>...</tr>');

   }

});

© www.soinside.com 2019 - 2024. All rights reserved.