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">×</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?– Jéf Bueno
I put it on but it still won’t close
– usersantos
Post the button with the event, please.
– Randrade
I have this function to close Function close(){ $('#myModal'). modal('Hide'); };
– usersantos
button <button type="button""button""onclick="close()" class="btn btn-default" data-Dismiss="modal">Close</button>
– usersantos
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/
– usersantos
Edit your question, and add the code to it. It’s easier for others to analyze.
– Randrade
edited your question to put the bootstrap Cdn, strange that the Close button worked normally.
– Tobias Mesquita
Here is working this code.
– Diego Souza
but using different files?
– usersantos
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?
– usersantos
data-dismiss="modal"
already executes the action of closing the modal. Why put a method to do the same thing?– Ivan Ferrer
@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.
– Paulo Weverton