且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在jQuery中的两个类之间切换

更新时间:2023-10-30 10:06:34

这可能是因为当你绑定这些函数时,没有结果$(。portlet-header .ui-icon-plusthick )。它没有找到它。您可以将此绑定添加到$(。portlet-header .ui-icon-minusthick)。在添加ui-icon-plusthick类之后,click(function(){...)。

It probably because when you bind those functions there are no results for $(".portlet-header .ui-icon-plusthick"). It doesn't find it. You may add this binding to $(".portlet-header .ui-icon-minusthick").click(function() { ... after adding "ui-icon-plusthick" class.

编辑:
替代解决方案可以是:

Alternative solution could be:

$(".portlet-header .ui-icon-minusthick").toggle(function() {
        $(this).removeClass("ui-icon-minusthick");
        $(this).addClass("ui-icon-plusthick");
        $(this).parents(".portlet:first").find(".portlet-content").toggle();
    }, function() {
        $(this).removeClass("ui-icon-plusthick");
        $(this).addClass("ui-icon-minusthick");
        $(this).parents(".portlet:first").find(".portlet-content").toggle();
    });


b $ b

所以第一次点击是第一个函数,第二次点击是第二个函数。

So first click would be first function and second click would be second function.