如果通过Ajax加载引导程序,如何在引导程序中打开模式? [英] How to open a modal in bootstrap if this is loaded via ajax?

查看:99
本文介绍了如果通过Ajax加载引导程序,如何在引导程序中打开模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用div,其中通过Ajax进行模态.加载div及其模态后,该按钮将不会打开模态.下面的代码是模态结构,它只是一个来自引导程序的纯模态,并且此代码已加载通过ajax:

I am calling a div where the modal is via Ajax. Once the div and its modal has been loaded, the button won't open the modal. The code below is the modal structure, it is just a plain modal from bootstrap, and this has been loaded via ajax:

<div class="ajax-loaded-item">
 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="myModalZ">Large modal</button>

 <div class="modal fade" id="myModalZ" tabindex="-1" role="dialog" aria-labelledby="myModalLabelZ" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h2 class="modal-title" id="myModalLabelS">Filter our work</h2>
            </div>
            <div class="modal-body">
                Content.....
            </div>
        </div>
    </div>
 </div>
</div>

如果在这种情况下我需要重新加载bootstrap.js,因为现在通过ajax加载了内容,现在是模态jQuery了,在我自己的ajax回调之后,我可以执行某种init模态调用吗? /p>

If it is the case that I need to reload bootstrap.js where the modal jQuery is as the content is now loaded via ajax, is there a sort of init modal call I can do after my own ajax callback?

推荐答案

您可以使用jQuery打开模式:

You can use the jQuery to open the modal:

$(document).ready(function(){
    $('button[data-target="myModalZ"]').click(function(){
        $('#myModalZ').modal('show');
    });
});

更多文档在此处.

已编辑

$(document).ready(function(){
    $('button[data-target="myModalZ"]').click(function(){
        if($('#myModalZ').length){
           $('#myModalZ').modal('show');
        } else {
           alert('Your message');
        }
    });
});

这篇关于如果通过Ajax加载引导程序,如何在引导程序中打开模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆