【问题标题】:How to remove a CSS class from all same level table rows When a Row is Selected?选择行时如何从所有相同级别的表行中删除 CSS 类?
【发布时间】:2012-03-29 19:16:56
【问题描述】:
$('table tbody tr').click(function () {
            // how to remove clickedRow class from all same level rows?
            $(this).addClass('clickedRow');
        });

When a row is selected, I'd like to remove the clickedRow css class from all other rows of the same table and only add it to the currently selected row.

我的页面中有多个表格,因此每次点击都应仅在同一个表格的上下文中执行上述操作。

这怎么可能?

谢谢,

【问题讨论】:

    标签: jquery asp.net html css class


    【解决方案1】:

    你可以用这个:

    $('table tbody tr').click(function () {
        $(this).siblings().removeClass('clickedRow');
    }
    

    它将从所有同级行中删除您的 css 类

    【讨论】:

      【解决方案2】:
      $(this).siblings('.clickedRow').removeClass('clickedRow');
      

      【讨论】:

        猜你喜欢
        • 2022-01-13
        • 1970-01-01
        • 2017-08-29
        • 1970-01-01
        • 1970-01-01
        • 2012-06-07
        • 2020-10-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多