2016-05-17 565 views
-1

我想创建弹出窗口。 但我有一些问题:
弹出窗口应该在点击它之后消失。但在我的解决方案弹出消失,当我点击里面。 这里是我的代码创建弹出窗口

<div class="popup__show">Click Me</div> 
<div class="popup__container"> 
    <div class="popup"> 
    hellohellohellohellohellohellohellohellohellohellohellohello 
    </div> 
</div> 

jQuery的

$(document).ready(function() { 
    $('.popup__show').click(function() { 
     $('.popup__container').show(); 
    }); 
    $('.popup__container').click(function() { 
     $('.popup__container').hide(); 
    }); 
}); 

https://jsfiddle.net/fw1d59Lz/ - 小提琴 谢谢您的回答和索里,我的英语。

+0

你可以使用自动关闭的引导程序,当你点击外部弹出窗口时没有任何附加代码 – DevelopmentIsMyPassion

+0

谢谢,但我需要解决方案,无需自举) – Hlushenok

+0

呃...没有任何额外的代码,除了Bootstrap。 :) – SimianAngel

回答

0

这可能帮助你

$('.popup__container').click(function(e) { 
if (e.target !== this) 
return; 
$('.popup__container').hide(); 
}); 
1

在你的jQuery添加这一点,你很好去 -

$('.popup').click(function(evt) { 
    evt.stopPropagation(); 
    }); 
1

事件泡沫升起。所以当你点击.popup时,.popup__container会听到它,除非你停下来。为此,请致电stopPropagation()参加活动。

$(document).ready(function() { 
    $('.popup__show').click(function(e) { 
     $('.popup__container').show(); 
    }); 
    $('.popup').click(function(e) { 
     e.stopPropagation(); 
    }); 
    $('.popup__container').click(function(e) { 
     $('.popup__container').hide(); 
    }); 
});