0

我有这个 html 标记,我想使用 jQuery 选择一些行。

当按下“cerrar”类的按钮时,我想在同一个按钮之前选择“隐藏”类的 3 tr

 <tr class='main'>
            <td class='table-sub-title'> 
                Test
            </td>
            <td class='table-sub-title'>
                Test
            </td>
            <td class='table-sub-title'>
                Test
            </td>
            <td class='table-sub-title'>
                Test
            </td>
        </tr>
        <tr class='hidden'> <!-- ********* Select this <tr> ********* -->
            <td class='noborder'>
                Test
            </td>
            <td class='noborder'>
                Test
            </td>
            <td class='noborder'>
                Test
            </td>
            <td class='noborder'>
                Test
            </td>
        </tr>
        <tr class='hidden'> <!-- ********* Select this <tr> ********* -->
            <td class='noborder'>
                Test
            </td>
            <td class='noborder'>
                Test
            </td>
            <td class='noborder'>
                Test
            </td>
        </tr>
        <tr class='hidden'> <!-- ********* Select this <tr> ********* -->
            <td class='noborder'>
                Test
            </td>
            <td class='noborder'>
                Test
            </td>
            <td class='noborder'>
            </td>
            <td class='noborder'>
                <input type='button' name='Cancelar' value='Cancelar' class='cerrar' />
            </td>
        </tr>
        <tr class='main'>...
    <!-- Repeat -->
4

1 回答 1

4

你可以这样做:

$('.cerrar').click(function(){

    // Get all the tr's with hidden class before button
    var TRs = $(this).closest('tr').prevUntil("tr.main").andSelf();

});
于 2013-01-15T14:06:38.160 回答