0

我有这张桌子:

<table border="0" class="tab_cadrehov">
       <tbody>
           <tr class="tab_bg_1">
               <td valign="top"><a id="User_245_245" href="/dailyTickets/front/contacts.form.php?id=245">Gov0N</a></td>
               <td valign="top">ContactName</td>
               <td valign="top"><a href="mailto:ContactUser@gmail.com">ContactUser@gmail.com</a></td>
            </tr>
            <tr class="tab_bg_2">
                <td valign="top"><a id="User_695_695" href="/dailyTickets/front/contacts.form.php?id=695">iLgOP</a></td>
                <td valign="top">ihi</td>
                <td valign="top"><a href="mailto:yassYassine@gmail.com">yassYassine@gmail.com</a></td>
             </tr>
       </tbody>
    </table>

我想要的是删除 ( tr, table) 中每个第一个 td 中的 a 元素,然后将删除的 a 元素赋予( , ) 中的第二个td元素,如下所示:trtable

  <tr class="tab_bg_1">
                   <td valign="top">Gov0N</td> // delete the a element from here , but keep the inside text  
                   <td valign="top"><a id="User_245_245" href="/dailyTickets/front/contacts.form.php?id=245">ContactName</a></td> // add it here , around the text
                .........
   </tr>
   <tr class="tab_bg_2">
                    <td valign="top">iLgOP</td>
                    <td valign="top"><a id="User_695_695" href="/dailyTickets/front/contacts.form.php?id=695">ihi</a></td>
                   .....

    </tr>
4

1 回答 1

2
$('tr').each(function() {
    var link = $(this).find('td:first a');
    text_of_second_td = $(this).find('td:nth-child(2)').text();
    $(this).find('td:first').html(link.text()); //Link's text to the first td
    link.text(text_of_second_td); //Replace Link's text by the second td's text
    $(this).find('td:nth-child(2)').html(link); //Link to the second td       
});

http://jsbin.com/afutir/1/

于 2013-02-23T12:48:19.640 回答