【问题标题】:Close button on modal not working...what am i doing wrong?模式上的关闭按钮不起作用......我做错了什么?
【发布时间】:2017-06-17 21:47:35
【问题描述】:

我制作了一个模式,当单击它时会弹出一个图像,但由于某种原因我无法让关闭按钮工作。有人可以检查我的代码,看看我哪里出错了吗?或者给我一些建议...谢谢!

<div id = "myModal" class = "modal">
        <div class = "modal-content">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <!-- Modal Content (The Image) -->
            <img class="modal-content" id="mimg">

            <!-- Modal Caption (Image Text) -->
            <div id="caption"></div>
        </div>
    </div>
    <img id="myImg" src="http://i0.kym-cdn.com/photos/images/newsfeed/001/023/007/f29.png" alt="Trolltunga, Norway" width="300" height="200">

【问题讨论】:

  • 这是引导程序 (3) 吗?请添加标签。

标签: html twitter-bootstrap twitter-bootstrap-3 modal-dialog


【解决方案1】:

简单的例子,如果你使用 bootstrap,请确保使用 bootstrap 方式。

另外,请确保引用正确。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

#myImg {
  width: 100%;
  height: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>

<div id="myModal" class="modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      <!-- Modal Content (The Image) -->
      <img id="myImg" src="https://pbs.twimg.com/media/BU27_rrCYAAckFP.jpg" alt="Trolltunga, Norway">
      <!-- Modal Caption (Image Text) -->
      <div id="caption">Modal Caption (Image Text)</div>
    </div>
  </div>
</div>

【讨论】:

  • 现在试试 broski
  • 我终于搞定了,非常感谢!!原来它是我的 CSS 中的东西......我现在正在弄清楚......祝福你
【解决方案2】:

您的代码不完整。尝试添加如下

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
Try it Yourself »

【讨论】:

  • 你使用 bootstrap.js 吗?打开您的检查并查看控制台选项卡中显示的内容
  • 只是不喜欢我用过的图片,其他什么都没有
  • jquery.min.js:3 混合内容:“preview.c9users.io/cstephens1911/theartisanemporium/…”处的页面是通过 HTTPS 加载的,但请求了不安全的图像“i.dailymail.co.uk/i/pix/2017/03/13/13/…”。此内容也应通过 HTTPS 提供。
  • @Breevie 您的图片由没有 HTTPS 的站点托管,它是 HTTP,通常不安全。试试这个链接https://pbs.twimg.com/media/BU27_rrCYAAckFP.jpg
猜你喜欢
  • 1970-01-01
  • 2014-07-27
  • 2012-11-19
  • 1970-01-01
  • 2012-11-07
  • 2013-02-08
  • 1970-01-01
  • 2014-02-16
  • 1970-01-01
相关资源
最近更新 更多