0

我有一张这样的桌子

<table>
  <tr>
    <td colspan="3" class="details">Some Text</td>
  </tr>
  <tr>
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
  </tr>
</table>

我怎样才能将 colspan 修复为普通表列,以便该列将被平均分配..?谢谢

4

1 回答 1

0

好吧,这是我想到的第一种方法:

$("td[colspan]").each(function() {   // find all tds that have a colspan specified
    var $td = $(this),
        cols = +$td.attr("colspan"); // get the value

    $td.attr("colspan",1);           // set the cell to have colspan 1
    for (var i = 1; i < cols; i++)   // add as many clones of the current cell
       $td.after($td.clone());       // as needed to replace the original colspan
});

演示:http: //jsfiddle.net/vpw8j/

于 2013-10-16T09:21:26.240 回答