【问题标题】:Unable to load Bootstrap Modal via Ajax无法通过 Ajax 加载引导模式
【发布时间】:2014-02-28 09:09:14
【问题描述】:

我的 html 代码为:

<button class="btn btn-default" id="openForm">
        New           
</button>

<!-- Modal -->
<div class="modal fade hide" id="formModal">
  <div class="modal-header">
    <h4>
        Form
    </h4>
  </div>

  <div class="modal-body" id="formModalBody">
  </div>

  <div class="modal-footer">
    <a href="#" data-dismiss="modal" class="btn">Close</a>        
  </div>
</div>

我的 Java 脚本如下:

$(document).on('click', '#openForm', function(e) {
e.preventDefault();

$("#formModalBody").html("");
$("#formModal").modal('show');

$.post('index.php/customers/view/-1/',
        {id: -1},
        function (html) {
            $("#formModalBody").html(html);
        }
    );
});

我正在使用 Twitter Bootstrap 和 Codeignitor。上面的post url是index.php/Controller/function

当我点击按钮时;我看不到引导模式。页面淡入,但没有可见的模式。

【问题讨论】:

    标签: php jquery ajax codeigniter twitter-bootstrap


    【解决方案1】:

    这适用于引导程序 3,可以单独由 html 触发,无需 javascript 它会运行 启动演示模式

    <!-- Modal -->
    <div class="modal fade" id="myModal" 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-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
          </div>
          <div class="modal-body" id="formModalBody">
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>
    
    <!-- For javascript -->
    $.post('index.php/customers/view/-1/',
            {id: -1},
            function (html) {
                $("#formModalBody").html(html);
            }
    );
    

    【讨论】:

      【解决方案2】:

      您应该使用anchor 链接而不是按钮,它将使用默认设置

       <a href="/model_link" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            Launch demo modal
          </a>
      

      href 链接响应代码将附加在

      <div class="modal-body" id="formModalBody">
      <!-- modal body -->
      </div>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-21
        • 2016-03-05
        • 2017-05-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多