仅选择< tr>使用jQuery之前在按钮之前的一些类 [英] Select only <tr> with some class before a button using jquery

查看:107
本文介绍了仅选择< tr>使用jQuery之前在按钮之前的一些类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have this html markup and i want to select some rows using jQuery.

当按下"cerrar"类的按钮时,我想在同一按钮之前选择"strong"类的"<3> tr"

When pressing the button with class 'cerrar' i want to select the 3 tr with class 'hidden' before the same button

 <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 -->

推荐答案

您可以这样做:

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

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

});

这篇关于仅选择&lt; tr&gt;使用jQuery之前在按钮之前的一些类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆