如何按类删除表行

How to remove table rows by class?

本文关键字:删除 何按类      更新时间:2023-09-26

在我的HTML中,我有这样的东西:

<table id="registerTable">
    <tr class="leaderRegistration">
        <!--table contents-->
    </tr>
    <tr class="leaderRegistration">
        <!--table contents-->
    </tr>
    <tr>
        <!--table contents-->
    </tr>
</table>

我想根据注册的用户类型删除表中的某些行,所以在我的javascript中我有(user.AcountType是我在其他地方定义的枚举):

if(newSysAdmin.accountType !== User.AccountType.Leader){
    $('#registerTable tr.leaderRegistration').remove();
}

然而,它似乎不起作用。我也尝试过使用$('.leaderRegistration')选择行,但结果是一样的。有什么想法可以解释为什么这不起作用吗?

http://jsfiddle.net/WT3av/

<table id="registerTable">
<tr class="leaderRegistration">
    <td>Content</td>
</tr>
<tr class="leaderRegistration">
    <td>Content</td>
</tr>
<tr>
    <td>Content</td>
</tr>
</table>

您的代码有效。也许你没有包括jQuery?

此外,我真的希望你也检查服务器端的帐户类型,不要向客户端发送敏感信息。