【问题标题】:Bootstrap modal on page load not working页面加载时的引导模式不起作用
【发布时间】:2016-07-07 06:59:15
【问题描述】:

我正在尝试在 Rails 应用程序中加载我的显示页面时启动引导模式,我尝试的是:

show.html.erb

<div class='center'>
<div id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-image">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Confirm Your Shipment!</h4>
            </div>
            <p id="notice"><%= notice %></p>
            <div class="modal-body">
<p>
<h4>
  <strong>PickUp Location:</strong>
</h4>
<h5>
  <strong><%= @load.pickup %></strong>
</h5>

<h4>
  <strong>Delivery Location:</strong>
</h4>
<h5>
  <strong><%= @load.delivery %></strong>
</h5>

<p>
    <div class="modal-footer">
    <a href="/shipments" class="btn btn-primary">Confirm</a>
    <a href='edit_load_path' class="btn">Edit</a>
  </div>
        </div>
      </div>
    </div>

javascript

<script type="text/javascript">
  $(document).ready(function(){
    $("#myModal").modal('show');
  });
</script>

css

.modal-header {
    padding:9px 15px;
    border-bottom:1px solid #eee;
    background-color: #87CEEB;
    -webkit-border-top-left-radius: 5px;
    -webkit-border-top-right-radius: 5px;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
     border-top-left-radius: 5px;
     border-top-right-radius: 5px;
 }


.modal-dialog {
  padding-top: 15%;
}

.modal-image{
    background-image: url('/assets/sure.jpg');
    background-repeat:no-repeat;
    background-size:cover;
}

这以前可以工作,但在格式化我的电脑并在 rails 上安装新的 ruby​​ 时停止工作。

我的应用中有许多其他正常的页面模态,它们运行良好。

【问题讨论】:

    标签: jquery css ruby-on-rails twitter-bootstrap bootstrap-modal


    【解决方案1】:

    我刚刚将这篇文章中的所有代码粘贴到我的文件中,并且它工作正常。请确保您已导入 Bootstrap Javascript 文件和 jQuery 文件。

    如果没有,只需在你的 html 正文标签末尾添加:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    

    如果这对你有帮助,请告诉我:)

    【讨论】:

    • 嘿@callmeniko 能否请您添加您正在谈论的文章的链接
    • 我下载了新的 Bootstrap 并添加了您在此问题中发布的代码。我的意思是你的 show.html.erb 文件中的代码
    • 谢谢老兄,我也做了同样的事情,效果很好
    • 很高兴我们发现了错误:)
    • 嘿@callmeniko 有一个小问题,当我推送到heroku 时,我无法点击我的模态上的任何内容...它有一个像什么东西一样的黑色阴影...但是在本地主机中一切看起来都很好
    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 2019-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    相关资源
    最近更新 更多