1

jquery の show と hide に小さな問題があります。

クリックを有効にしてボックスを表示するボタンがあります。

ボックスの外側をクリックしてボックスをフェードアウトすることはできますか

これが私のコードです。

$('.normal-btn.interest').click(function(){
    $('.categories-wrap').fadeIn();
})

$('what needs to be here? ').click(function(){
    $('.categories-wrap').fadeOut();
})
4

3 に答える 3

1

clickはい、イベントを次のdocumentようにバインドできます。

$('.normal-btn.interest').click(function(e){

    // Prevent the event from bubbling up the DOM tree
    e.stopPropagation();
    $('.categories-wrap').fadeIn();
});

$(document).click(function(){
    $('.categories-wrap').fadeOut();
});
于 2013-10-09T11:33:38.663 に答える
1

これを試して:

$('.normal-btn.interest').click(function(e){
      e.stopPropagation();
     $('.categories-wrap').fadeIn();
});

$(document).not($(".normal-btn.interest")).click(function(){
    $('.categories-wrap').fadeOut();
});
于 2013-10-09T11:41:07.807 に答える