How to get twitter bootstrap modal to close (after initial launch)

前端 未结 10 852
半阙折子戏
半阙折子戏 2020-12-24 04:13

I\'m very much a noob, so I think I\'m overseeing something (probably obvious) with twitter bootstrap modal. What I am trying to do is get a modal to launch only on mobile.

相关标签:
10条回答
  • 2020-12-24 04:58

    $('#myModal').modal('hide') should do it

    0 讨论(0)
  • 2020-12-24 04:59

    According the documentaion hide / toggle should work. But it don't.

    Here is how I did it

    $('#modal-id').modal('toggle'); //Hide the modal dialog
    $('.modal-backdrop').remove(); //Hide the backdrop
    $("body").removeClass( "modal-open" ); //Put scroll back on the Body
    
    0 讨论(0)
  • 2020-12-24 05:00

    Add the class hide to the modal

    <!-- Modal Demo -->
    <div class="modal hide" id ="myModal" aria-hidden="true" >
    

    Javascript Code

     <!-- Use this to hide the modal necessary for loading and closing the modal-->
     <script>
         $(function(){
             $('#closeModal').click(function(){
                  $('#myModal').modal('hide');
              });
          });
     </script>
    
     <!-- Use this to load the modal necessary for loading and closing the modal-->
     <script>
         $(function () {
             $('#myModal').modal('show');
         });
      </script>
    
    0 讨论(0)
  • 2020-12-24 05:03

    .modal('hide') manually hides a modal. Use following code to close your bootstrap model

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

    Take a look at working codepen here

    Or

    Try here

    $(function () {
        $(".custom-close").on('click', function() {
            $('#myModal').modal('hide');
        });
    });
    <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.5/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
    
    <!-- Button trigger modal -->
    <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
      Launch demo modal
    </button>
    
    <!-- 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">&times;</button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
          </div>
          <div class="modal-body">
            
              
              <a class="custom-close"> My Custom Close Link </a>
              
              
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    0 讨论(0)
提交回复
热议问题