Jquery Bootstrap 4模态不';美元后无法正常工作。获取

Jquery Bootstrap 4模态不';美元后无法正常工作。获取,jquery,bootstrap-4,Jquery,Bootstrap 4,我的应用程序中有几个模态,它们似乎工作得很好,除了那些我通过$.Get友好地调用的模态 内容已加载,但按钮不起作用。我不能使用取消按钮、关闭按钮和提交按钮,但如果我按Enter键,我可以提交表单 以下是ajax调用的代码: $(document).on('click', '.open-modal', function(event) { var pageName = $(this).attr('pageName'); $.get(pageName, function(data) {

我的应用程序中有几个模态,它们似乎工作得很好,除了那些我通过$.Get友好地调用的模态

内容已加载,但按钮不起作用。我不能使用取消按钮、关闭按钮和提交按钮,但如果我按Enter键,我可以提交表单

以下是ajax调用的代码:

$(document).on('click', '.open-modal', function(event) {
    var pageName = $(this).attr('pageName');
    $.get(pageName, function(data) {
        let result = $(data).find('#copy-modal');
        $('#generic-modal').html(result);
    });
    $("#generic-modal").modal('show');
});
这是触发事件的按钮或链接的代码:

<button type='button' name="uid" id="openCompany" pageName="rt_users/empresas/{{$user->id}}" class="btn btn-info open-modal"> |
    <i class="material-icons">business</i>
    <div class="ripple-container"></div>
</button>
|
商业
这是通用模态代码:

<div id="generic-modal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                 <h4 class="modal-title"></h4>
             </div>
             <div class="modal-body"></div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
             </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

&时代;
接近

由于要将整个模态替换为另一个模态,因此DOM与函数启动时不同

您有两个选项,您可以只更改模式的内容(在本例中通常是这样做的),也可以在执行show函数之前刷新DOM对象

要刷新DOM对象,可能需要一些事件委派

我的建议是只使用选项一并替换此选项:

 $('#generic-modal').html(result);
为此:

 $('#generic-modal .modal-body').html(result);

为什么你要完全用一种模式替换另一种模式?你不应该只是把内容放在模态体中,而不是替换整个模态吗?这是正确的!谢谢你的评论,你真的帮了我的忙!