How does the modal box of Bootstrap pop up by itself?

when learning Bootstrap:

http://www.runoob.com/try/try.

this

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="-sharpmyModal">
    
</button>

Click the button and the modal box pops up. Which variable does it use to make the modal box pop up?

I want to enter the page and modal directly pops up if that variable doesn"t exist, instead of clicking the button and popping up again.

Mar.28,2021

check the official document first
https://v3.bootcss.com/javasc.

if you encounter problems.


look at the documents for yourself. After the page is loaded, you can call api to trigger it.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"> 
    <title>Bootstrap  - Modal</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 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">
                    
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    Modal
                </h4>
            </div>
            <div class="modal-body">
                
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                </button>
                <button type="button" class="btn btn-primary">
                    
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
    <script type="text/javascript">
            
          $(function(){
                   $('-sharpmyModal').modal('show')
          });
   </script>
</body>
</html>
Menu