简体   繁体   中英

Bootstrap modal does not show

I have the following bootstrap modal:

<div class="popupCover">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" onClick="closeModal()" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>    </button>
  </div>
  <div class="modal-body">
    <h4>Text1</h4>
    <p>Text2</p>
  </div>
</div>
</div>
</div>
</div>

I am trying to open it with

<script type="text/javascript">$('#myModal').modal('show')</script>

However, this does not work. Can anyone see the error? Thanks!

You should add jQuery and bootstrap.js files, and bootstrap script should be added after jQuery

You can see the working pen here

HTML:

    <div class="popupCover">
      <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" onClick="closeModal()" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>    </button>
            </div>
            <div class="modal-body">
              <h4>Text1</h4>
              <p>Text2</p>
            </div>
          </div>
        </div>
      </div>
    </div>

JS:

$('#myModal').modal('show');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM