本文介绍了模态上的关闭按钮不起作用...我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个模态,使单击图像时弹出该图像,但是由于某种原因,我无法使关闭按钮起作用.有人可以检查我的代码,看看我出了什么问题吗?或给我一些建议...谢谢!

I've made a modal that makes an image pop up when it's clicked but I can't get the close button to work for some reason. Can someone check my code and see where I went wrong? Or give me some suggestions...thank you!

<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">

推荐答案

简单的示例,如果您使用引导程序,请确保以引导程序方式进行操作.

Simple example, if you use bootstrap, make sure to do it the bootstrap way.

还要确保引用正确.

<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>

这篇关于模态上的关闭按钮不起作用...我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 23:14