modal poupop bootstrap

Asked

Viewed 255 times

1

I’m wearing a modal from bootstrap.

I call the modal after clicking on a onclick, that modal is on a page the part happens is that the button close-up does nothing for me.

var btAbrir = $("#btAbrir");
var myModal = $("#myModal");

function load(id){
  //$("#contentLoading").load("../temp/tst.php?id="+id +""); 
  myModal.modal('show');
}

function close(){ 
  myModal.modal('hide');
};

btAbrir.on("click", function () {
  load(0);
});
<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"/>
<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" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" onclick="close()" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
<button id="btAbrir" type="button" class="btn btn-default">Abrir Modal</button>

  • You don’t have to add an event onclick to the button close-up?

  • I put it on but it still won’t close

  • Post the button with the event, please.

  • I have this function to close Function close(){ $('#myModal'). modal('Hide'); };

  • button <button type="button""button""onclick="close()" class="btn btn-default" data-Dismiss="modal">Close</button>

  • Now this gives me this error Synchronous Xmlhttprequest on the main thread is deprecated because of its detrimental effects to the end user’s Experience. For more help, check http://xhr.spec.whatwg.org/

  • Edit your question, and add the code to it. It’s easier for others to analyze.

  • edited your question to put the bootstrap Cdn, strange that the Close button worked normally.

  • Here is working this code.

  • but using different files?

  • In a php web file I have a function to load the model and it opens but the function to close does not work. will be because it is in another file?

  • data-dismiss="modal" already executes the action of closing the modal. Why put a method to do the same thing?

  • @Ivanferrer is right. The close button tag would be <button type="button" data-Ismiss="modal" Aria-label="Close" class="close">. Remembering that you must be inside the modal div.

Show 8 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.