我一直在使用 jQuery 文档,并且我正在尝试设置一种情况,其中模式的内容是从单独的 html 文件填充的。所有文件都位于同一域、同一文件夹中。到目前为止,模式将在单击时启动,但没有从 html 文件中提取任何内容。我正在使用 Zurb Reveal 作为模态。
jQuery:
$('.video-btn').click(function (e) {
e.preventDefault();
var modalUrl = $(this).attr('href');
$('#myModal').load('modalUrl #vidModal').reveal({
animationspeed: 500,
animation: 'fadeAndPop',
dismissmodalclass: 'close-reveal-modal'
});
//$('.video-wrapper').children().show();
});
链接
<a href="modal1.html" class="info-btn video-btn">
<h2>Video</h2>
<p>Cambridge at a glance</p>
</a>
/*Outer modal hidden on page*/
<div id="myModal" class="reveal-modal"></div>/*Content that is in a file named modal1.html*/
<div id="vidModal" class="reveal-modal">
<div class="inner-modal">
<div class="modal-head">
<h2>Video</h2>
<p>Cambridge at a glance</p>
<a class="close-reveal-modal"></a>
</div>
<div class="modal-share-btns"></div>
<div class="video-wrapper">
<iframe id="vid" src="http://player.vimeo.com/video/20800836?api=1" width="700" height="400" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>
</div>
</div>
<!-- /inner-modal -->
</div>
最佳答案
您的代码应如下所示:
$('#myModal').load(modalUrl+'#vidModal')
在您的代码中,您加载网址 modalUrl #vidModal
,而不是存储在 modalUrl
中与 #vidModal
连接的网址
(根据评论更新)
关于javascript - .load() 没有从 html 文件中提取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14585679/