我需要将表行包装成div

时间:2013-09-04 15:23:57

标签: jquery

我需要将表行包装成div,我做

$('table tr').each(function(){
    $(this).insertBefore('<div>');
    $(this).insertAfter('</div>');
})

但似乎不起作用 UPDATE fidle http://jsfiddle.net/EsdR2/1/

1 个答案:

答案 0 :(得分:6)

如果你试图将它们划分为单独的部分而不是一行,那么可以尝试使用tbody方法。

<table class="table">
    <tbody class="first-part">
        <tr>
            <td>first</td>
        </tr>
    </tbody>
    <tbody class="second-part" style="display:none">
        <tr>
            <td>second</td>
        </tr>
    </tbody>
</table>

看到淡出后编辑然后你可以试试这个javascript ..

var firstPart = $('tbody.first-part');
var secondPart = $('tbody.second-part');

$('#SomeButton').click(function () {
    firstPart.fadeOut("fast");
    secondPart.fadeIn("slow");
});

这里是一个有fadeout工作的jsFiddle。 http://jsfiddle.net/u3fNL/1/