我想在单击复选框时更改字段集的类。

这是我所拥有的:

jQuery的

$(document).ready(function(){
    $("#<%=cbLimit.ClientID%>").click(function () {
        $("#fsLimit").removeClass(".active");
        $("#fsLimit").addCLass(".inactive");
    });
});


的CSS

.active {
    border: 1px solid #3f90cb;
    padding: 10px;
    margin: 10px;
}
.inactive {
    border: 1px solid #F0F0F0;
    padding: 10px;
    margin: 10px;
}


天冬氨酸

<fieldset id="fsLimit" class="active" >
    <legend >
        <asp:CheckBox ID="cbLimit" runat="server" /><asp:Label ID="lblLimit" runat="server" AssociatedControlId="cbLimit" text="Limit"/>
    </legend>
    <!--Some stuff-->
</fieldset>


什么都没发生。我试图只是在.click函数中放一个警报,并且效果很好。有人可以告诉我我在做什么错吗?

最佳答案

使用更改事件,并从addClass和removeClass方法的类名称中删除.

$("#<%=cbLimit.ClientID%>").change(function () {
    $("#fsLimit").removeClass("active"); //Removed .
    $("#fsLimit").addCLass("inactive"); //Removed .
});

07-24 21:58