简体   繁体   English

.load()没有从html文件中提取内容

[英].load() is not pulling in content from html file

I have been using the jQuery Docs and I am trying to set up a situation where the content of a modal is filled from a separate html file. 我一直在使用jQuery Docs,并且试图设置一种情况,即从单独的html文件填充模态的内容。 All files are on the same domain, same folder. 所有文件都在相同的域,相同的文件夹中。 So far, the modal will launch on click, but no content is being pulled in from the html file. 到目前为止,该模式将在单击时启动,但不会从html文件提取任何内容。 I'm using Zurb reveal for modal. 我正在使用Zurb模式显示模式。

jQuery: 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();
});

The Link 链接

<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>

your code should look like this: 您的代码应如下所示:

$('#myModal').load(modalUrl+ ' #vidModal')

in your code you load the url modalUrl #vidModal and not the url stored in modalUrl concatenated with #vidModal 在你的代码加载的URL modalUrl #vidModal ,而不是存储在URL modalUrl与串联#vidModal

(Updated base on comments) (根据评论更新)

The problem: 问题:

$('#myModal').load('modalUrl #vidModal')

modalURl is being included as part of the string literal. modalURl被包含为字符串文字的一部分。

You should do: 你应该做:

$('#myModal').load(modalUrl + ' #vidModal')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM