【发布时间】:2018-08-09 13:26:06
【问题描述】:
我正在使用模式查询将 div 附加到正文,并且按钮与模式相关联。我正在尝试使用按钮关闭模式,我的代码如下。它看起来像是事件触发的问题。
$('a.launch-youtube-modal').click(function(event) {
event.preventDefault();
$('body').append([
'<div class="youtube-modal">',
'<div class="youtube-modal-container"><div class="youtube-modal-video-container">',
'<iframe width="671" height="495" src="'+ $(this).attr('href') +'" frameborder="0" allowfullscreen id="youtube-video"></iframe>',
'<button class="ss-icon ss-gizmo youtube-close">close</button>',
'</div></div>',
'</div>'
].join(''));
function closeYoutubeModal() {
if (!video) return;
video.jQYT('destroy');
$('.youtube-modal').remove();
}
$('.youtube-modal .youtube-close').click(function () {
closeYoutubeModal();
});
});
【问题讨论】:
标签: javascript jquery events event-handling bootstrap-modal