简体   繁体   English

如何从AJAX打开的Modal内部的链接加载jQuery Modal

[英]How to load a jQuery Modal from links inside an AJAX opened Modal

I've read a few answers to this but none match my issue: 我已经阅读了一些答案,但是没有一个匹配我的问题:

  1. I would like to load html into a Modal from an AJAX request - (which I already have and it works great) 我想从AJAX请求中将html加载到Modal中((我已经拥有,并且效果很好)

  2. I would like to click on a link inside the loaded modal which then opens up another Modal with more details which could have more links to Modals to open again. 我想单击已加载模态内的链接,然后打开另一个具有更多详细信息的模态,该模态可能有更多的模态链接可再次打开。 - I can then drag these around the page and have lots open. -然后,我可以在页面上拖动这些内容,并打开很多内容。

So obviously when I click a link in the loaded Modal it goes to that page, rather than opens it in another Modal. 因此,很明显,当我单击加载的Modal中的链接时,它将转到该页面,而不是在另一个Modal中打开它。

<script type="text/javascript">
$(document).ready(function() {
    $('a.open').each(function() {
        var $link = $(this);
        var $dialog = $('<div></div>')
            .load($link.attr('href'))
            .dialog({
                autoOpen: false,
                title: $link.attr('title'),
                width: 600
            });

        $link.click(function() {
            $dialog.dialog('open');
            return false;
        });
    });
});

Then my HTML is 然后我的HTML是

<a href="reports?report=cows" class="open" title="Cows" class="open" >List Cows</a>

The in the loaded Modal the html could be: 在已加载的Modal中,html可能是:

<a href="reports?report=cow_detail" class="open" title="Cow Detail" class="open" >Cow #43</a> <br />...

And this would then open another Modal with the detail. 然后,这将打开另一个带有细节的模态。

So I'm looking or expecting to be able to load that first bit of JavaScript after the modal loads to get the newly created class="open" tags that wouldn't be seen when on document load. 因此,我正在寻找或期望能够在模式加载后加载JavaScript的第一位,以获取新创建的class =“ open”标签,该标签在文档加载时不会显示。

Much appreciated! 非常感激!

Use the code when the modal window is loaded. 加载模式窗口时使用该代码。

$('#myModal').on('show.bs.modal', function (e) {
    $('a.open').each(function() {
        var $link = $(this);
        var $dialog = $('<div></div>')
            .load($link.attr('href'))
            .dialog({
                autoOpen: false,
                title: $link.attr('title'),
                width: 600
            });

        $link.click(function() {
            $dialog.dialog('open');
            return false;
        });
    });
});

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

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