首页>Program>source

使用新的Twitter Bootstrap版本:Bootstrap 4 alpha,我无法使Modal在远程模式下工作.它在Bootstrap 3上运行良好。在bootstrap 4下,我正在弹出窗口,但是没有加载模型主体.没有电话到 myRemoteURL.do 加载模型主体。

代码:

<button type="button" data-toggle="modal" data-remote="myRemoteURL.do" data-target="#myModel">Open Model</button>
<!-- Model -->
<div class="modal fade" id="myModel" tabindex="-1"
    role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <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>
                <h3 class="modal-title" id="myModalLabel">Model Title</h3>
            </div>
            <div class="modal-body">
                <p>
                    <img alt="loading" src="resources/img/ajax-loader.gif">
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Submit</button>
            </div>
        </div>
    </div>
</div>
最新回答
  • 2021-1-11
    1 #

    发现了问题:他们在引导程序4中删除了远程选项

    remote :此选项从v3.3.0开始不推荐使用,并将在v4中删除.我们建议改为使用客户端模板或数据绑定框架,或者自己调用jQuery.load。

    我使用JQuery来实现此已删除的功能。

    $('body').on('click', '[data-toggle="modal"]', function(){
            $($(this).data("target")+' .modal-body').load($(this).data("remote"));
        }); 
    

  • 2021-1-11
    2 #

    根据官方文档,我们可以执行以下操作(https://getbootstrap.com/docs/4.1/components/modal):

    $('#exampleModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget) // Button that triggered the modal
        var recipient = button.data('whatever') // Extract info from data-* attributes
        // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
        // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
        var modal = $(this)
        modal.find('.modal-title').text('New message to ' + recipient)
        modal.find('.modal-body input').val(recipient)
    })
    

    所以,我认为这是最好的方法:

    $('#modal_frame').on('show.bs.modal', function (e) {
        $(this).find('.modal-content').load(e.relatedTarget.href);
    });
    

    Adapt to your needs

  • 2021-1-11
    3 #

    正如其他答案和Bootstrap文档所指出的那样, Bootstrap 4 需要处理 show.bs.modal 事件,以将内容加载到模式中.可用于从HTML字符串或远程URL加载内容.这是 working example ...

    $('#theModal').on('show.bs.modal', function (e) {
        var button = $(e.relatedTarget);
        var modal = $(this);
        // load content from HTML string
        //modal.find('.modal-body').html("Nice modal body baby...");
        // or, load content from value of data-remote url
        modal.find('.modal-body').load(button.data("remote"));
    });
    

    Bootstrap 4远程URL演示


    另一种选择是一旦从Ajax调用返回数据,就打开模态。

     $.ajax({
           url: "http://someapiurl",
           dataType: 'json',
           success: function(res) {
               // get the ajax response data
               var data = res.body;
               // update modal content
               $('.modal-body').text(data.someval);
               // show modal
               $('#myModal').modal('show');
           },
           error:function(request, status, error) {
               console.log("ajax call went wrong:" + request.responseText);
           }
      });
    

    Ajax演示中的Bootstrap 4加载模式

  • 2021-1-11
    4 #

    在Asp.NET MVC中,这对我有用

    html

    <a href="#" onclick="Edit(1)">Edit item</a>
    <div class="modal" id="modalPartialView" />
    

    jquery

    <script type="text/javascript">
            function Edit(id)
            {
                $.ajax({
                    url: "@Url.Action("ActionName","ControllerName")",
                    type: 'GET',
                    cache: false,
                    data: {id: id},
                }).done(function(result){
                    $('#modalPartialView').html(result)
                    $('#modalPartialView').modal('show') //part of bootstrap.min.js
                });
            }
    <script>
    

    Action

    public PartialViewResult ActionName(int id)
    {
       // var model = ...
       return PartialView("_Modal", model);
    }
    

  • 2021-1-11
    5 #

    如果使用Jquery slim版本(如所有Bootstrap 4文档和示例中一样),则加载功能将失败

    您需要使用完整版的Jquery

  • android:触发按钮onclick后如何保持alertdialog打开?
  • security:将密码以纯文本格式存储在php变量或php常量中是否可行?