javascript - .removeClass() 只工作一次

标签 javascript jquery html

我已经在 HTML 4x2 中布置了一些图像。我的脚本目前正在使用 .addClass() 放大每张图片,但只会在图库中的第一张图片上使用 .removeClass()。

我如何才能将 .removeClass() 应用于每张图片? - 这是我的代码:

$(document).ready(function () {
    $('#fig').delegate('img', 'click', function () {
        $(this).addClass("imgbig");
        $('.xbutton').stop(true, true).fadeTo(800, 1);
        $("#fig").stop(true, true).addClass("f1");
    });

    $('.xbutton').click(function () {
        $('#imgSmall').removeClass("imgbig");
        $('.xbutton').stop(true, true).fadeOut(800, 0);
        $("#fig").stop(true, true).removeClass("f1");
    });
});

最佳答案

在这里$('#imgSmall').removeClass("imgbig")你选择了id为imgSmall的图片,而不是你所有的图片。

我想你应该像下面这样重写你的回调:

$('.xbutton').click(function(){
    $(".imgbig").removeClass("imgbig");
    $('.xbutton').stop(true, true).fadeOut(800, 0);
    $("#fig").stop(true, true).removeClass("f1");
});

关于javascript - .removeClass() 只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31996164/

相关文章:

javascript - Flow - 通过 props 传递的渲染组件

javascript - 遍历选择中的所有选项并将值添加到选项名称

javascript - 套接字 IO V0.7 : How to send message to more that one specific client

javascript - 根据鼠标的位置更改图像位置 我怎样才能让它在 ie 中工作?

jquery - 如何让 jQuery Mobile 停止破坏 Ember.js 网站?

javascript - 使用 jQuery 删除类的正确方法

javascript - 如何在我的 jQuery 导航菜单中正确定位箭头?

javascript - jQuery 点击 td 切换复选框

javascript - 单击被图像覆盖的按钮

jQuery 显示隐藏 li 和 ul