How to enable links within 'return false' div.click

时间:2016-11-09 06:57:05

标签: javascript

I have been playing with the modal here, and so far I've learned a good bit, but still need your help, guys. I didn't want the modal to close when you clicked it randomly (eg. scroll, etc.), so the return false event was added on click. But how would you go about allowing links inside (.modal) to still work?

$('#modal-container').click(function(){
        $(this).addClass('out');
        $('body').removeClass('modal-active');
});

$('#close-btn').click(function(){
        $('#modal-container').click();
});

$('.modal').click(function(e){
        return false;
});

Thanks again for your help! ^_^

1 个答案:

答案 0 :(得分:0)

可能应该检查点击了哪个元素。如果不仅锚定返回false。

$('.modal').click(function(e) {
    if (!($(e.target).is('a')))
    {
      return false;
    }           
});