Mam przycisk na mojej stronie, że po naciśnięciu wyzwala niektóre funkcje javascript i jedną z tych funkcji javascript, aby otworzyć modala bootstrap, ale nie mogę go uruchomić. Oto mój kod ... proszę o pomoc.Jak wyświetlić modał bootstrap z funkcji javascript?
//elsewhere on the form is the button that triggers the javascript
<a href="#" class="btn btn-danger" id="cancelPObtn" data-dismiss="modal">Yes, cancel it</a>
<!-- CANCEL A PO MODAL -->
<div class="modal hide fade" id="error-dialog" style="display: none;">
<div class="modal-header">
<a class="close" data-dismiss="modal">x</a>
<h3>Cancel Purchase Order?</h3>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<a href="#" class="btn btn-danger btn-modal btn-cancel" data-dismiss="modal">Yes, cancel it</a>
<a href="#" class="btn" data-dismiss="modal">Nevermind</a>
</div>
</div>
$('.btn-danger').click(function(event) {
if(some random conditional statement){
//some stuff happens here
}
else{
//Show form validation error modal-- I know this part is triggered but the modal will not show
$("#error-dialog").modal("show");
}
});
Przypadkowo usunąłem if() po wpisaniu pytania. Prawdziwym rozwiązaniem było usunięcie stylu tagu style = "display: none;" z modalu. – silvster27
@JSilva Jeśli to nie był problem z twoim pytaniem, nie akceptuj tej odpowiedzi. To po prostu myli ludzi, kiedy czytają to pytanie. – idmean