Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Uruchomienie modal-a po załadowaniu strony
krzesik
post 5.03.2017, 19:44:20
Post #1





Grupa: Zarejestrowani
Postów: 516
Pomógł: 1
Dołączył: 25.08.2012

Ostrzeżenie: (0%)
-----


Witam, pytanie trywialne , ale sam już nie wiem gdzie robię błąd
mam modala
  1. <button id="myBtn">Open Modal</button>
  2.  
  3. <!-- The Modal -->
  4. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  5.  
  6. <!-- Modal content -->
  7. <div class="modal-content">
  8. <div class="modal-header">
  9. <span class="close">&times;</span>
  10. <h2>Tilte</h2>
  11. </div>
  12. <div class="modal-body">
  13. <p>Some text in the Modal Body</p>
  14. <p>Some other text...</p>
  15. </div>
  16. <div class="modal-footer">
  17. <h3>Footer</h3>
  18. </div>
  19. </div>
  20.  
  21. </div>


później scripty
  1. <script type="text/javascript">
  2. // Get the modal
  3. var modal = document.getElementById('myModal');
  4.  
  5. // Get the button that opens the modal
  6. var btn = document.getElementById("myBtn");
  7.  
  8. // Get the <span> element that closes the modal
  9. var span = document.getElementsByClassName("close")[0];
  10.  
  11. // When the user clicks the button, open the modal
  12. btn.onclick = function() {
  13. modal.style.display = "block";
  14. }
  15.  
  16. // When the user clicks on <span> (x), close the modal
  17. span.onclick = function() {
  18. modal.style.display = "none";
  19. }
  20.  
  21. // When the user clicks anywhere outside of the modal, close it
  22. //window.onclick = function(event) {
  23. // if (event.target == modal) {
  24. // modal.style.display = "none";
  25. // }
  26. // }

uruchamia się po wciśnięciu przycisku, ale jak zrobić aby uruchamia się po załadowaniu strony
zamiast powyższego dawałem:
  1. <script type="text/javascript">
  2. $(document).ready( function(){
  3. $('#myBtn').modal('show');
  4. });
  5.  


ale bez efektu..
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
nospor
post 5.03.2017, 19:47:45
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




#myBtn to przeciez button... Jak chcesz pokazac modal to masz zrobic modal na div a nie na button


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
krzesik
post 5.03.2017, 19:57:51
Post #3





Grupa: Zarejestrowani
Postów: 516
Pomógł: 1
Dołączył: 25.08.2012

Ostrzeżenie: (0%)
-----


ok, poprawiłem, ale dalej brak zamierzonego efektu

po korekcie mam tak:
<script type="text/javascript">
$(document).ready( function(){
$('#myModal').modal('show');
});

</script>
Go to the top of the page
+Quote Post
nospor
post 5.03.2017, 20:05:32
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




wg kodu z pierwszego posta nie uzywasz pluginu modal, tylko recznie pokazujesz kod.

Wiec nie:
$('#myModal').modal('show');
a:
$('#myModal').show();

Zakladam ze chociaz jQuery masz zaladowane wink.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
krzesik
post 5.03.2017, 20:10:03
Post #5





Grupa: Zarejestrowani
Postów: 516
Pomógł: 1
Dołączył: 25.08.2012

Ostrzeżenie: (0%)
-----


:-) teraz jest git
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 02:38