Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Auto click po załadowaniu strony
wrkilu
post 1.12.2020, 23:09:54
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 1.12.2020

Ostrzeżenie: (10%)
X----


Hej,
Mam na stronie 2 buttony, które gdy się je kliknie wyświetlają na stronie jakieś odpowiednie teksty.
I teraz chciałbym aby po załadowaniu strony od raz wyświetlił się tekst tak jakby ktoś kliknął właśnie jeden z tych buttonów.


Buttony są zdefniowane tak:
Cytat
<div class="tab">
<button class="tablinks" onclick="usluga(event, 'konta-ftp')">Konta FTP</button>
<button class="tablinks" onclick="usluga(event, 'abonament')">Abonament</button>
</div>


A skrypt JS tak:
Cytat
<script>
function usluga(evt, name) {
// Declare all variables
var i, tabcontent, tablinks;

// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}

// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}

// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(name).style.display = "block";
document.getElementById(name).style.borderStyle = "hidden";

evt.currentTarget.className += " active";
}

</script>


I to jest wersja na kliknięcie ręczne, które działa.
I teraz co dodać żeby jeden z nich się automatycznie kliknął ? Będę bardzo wdzięczny za pomoc bo musze to zrobić z doskoku a programistą JSa nie jestem,
pozdrawiam

Ten post edytował wrkilu 1.12.2020, 23:10:32
Go to the top of the page
+Quote Post
gitbejbe
post 2.12.2020, 07:16:16
Post #2





Grupa: Zarejestrowani
Postów: 515
Pomógł: 63
Dołączył: 27.08.2012

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


  1. <div class="tab">
  2. <button id="btn1" class="tablinks" onclick="usluga(event, 'konta-ftp')">Konta FTP</button>
  3. <button id="btn2" class="tablinks" onclick="usluga(event, 'abonament')">Abonament</button>
  4. </div>
  5.  


za funkcją usługa - przed samym znacznikiem zamykającym </script> dodaj:

document.getElementById('btn1').click();

Ten post edytował gitbejbe 2.12.2020, 07:16:39
Go to the top of the page
+Quote Post
wrkilu
post 2.12.2020, 09:51:27
Post #3





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 1.12.2020

Ostrzeżenie: (10%)
X----


Rządzisz Panie rządzisz smile.gif
działa i pozdrawiam serdecznie

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.03.2024 - 08:25