1

I am looking for a jquery script to replace the th with td for this specific span.

<span id="ViewPayment_LblPayment">
  <table width="500" border="0" cellspacing="0" cellpadding="0">
    <tbody>
      <tr>
        <th>Due Date</th>
        <th>Amount Due</th>
        <th>Location</th>
      </tr>
      <tr>
        <td>6/14/2011</td>
        <td>$170.99</td>
        <td>MAIL</td>
      </tr>
    </tbody>
  </table>
</span>

I am very new to jquery and am scheduled for some courses so please provide a direct code answer instead of a similar answer.

4

2 回答 2

3

尝试

var $span = $('#ViewPayment_LblPayment');

$span.find('th').wrapInner('<td />').contents().unwrap();
$span.find('tbody').contents().unwrap();

演示:小提琴

于 2013-09-05T16:46:01.047 回答
1

我会使用replaceWith

$('#ViewPayment_LblPayment th').replaceWith(function(){
    return $("<td />", {html: $(this).html()});
});

这是这个代码在行动 - http://jsfiddle.net/maximua/AAtSX/2/

于 2013-09-05T16:54:43.230 回答