0

$('.transparent-close').click(function(){ ...}); 内部调用的事件 似乎没有工作。可能是因为它在另一个 .click() 事件中吗?

$('#featured-top').click(function(){
    $(this).animate({'top':'-318px'}, 600, 'easeOutBounce');
    $('#featured-top-container').animate({'margin':'260px 0 0 117px'}, 600, 'easeOutBounce');
    $('#wrap').animate({'margin-top':'365px'}, 600, 'easeOutBounce');

    //Add transparent background for click out
    $(document.body).append('<div class="transparent-close"></div>');
    $('.transparent-close').click(function(){
        $('#featured-top').animate({'top':'-318px'}, 600, 'easeOutBounce');
        $('#featured-top-container').animate({'margin':'260px 0 0 117px'}, 600, 'easeOutBounce');
        $('#wrap').animate({'margin-top':'365px'}, 600, 'easeOutBounce');
        $(this).remove();
    });
});
4

1 回答 1

0

我会使用:

$('body').append(
    $('<div></div>')
        .addClass('transparent-close')
        .on('click',function(){
            //...
        });
);

即使我不知道确切原因,我在使用 click 函数作为事件侦听器时也遇到了问题。

于 2012-12-02T02:26:16.460 回答