Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]nie działa style.display ?
robos85
post
Post #1





Grupa: Zarejestrowani
Postów: 466
Pomógł: 11
Dołączył: 21.09.2006
Skąd: Szczecin

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


mam kod html:
  1. echo'<a href="#" onclick="show1()">div1</a><br />';
  2. echo'<a href="#" onclick="show2()">div2</a><br />';
  3. echo'<div id="first" style="display:none;clear:both;">DIV 11111111111111111111111111111111</div>';
  4. echo'<div id="second" style="display:none;clear:both;">DIV 22222222222222222222222222222222</div>';

i JS:
Kod
var div1=document.getElementById('first');
var div2=document.getElementById('second');
function show1(){
    div1.style.display="block";
    div2.style.display="none";    
}
function show2(){
    div1.style.display="none";
    div2.style.display="block";    
}


Lecz po kliknięciu w link, nic się nie dzieje? Co nie tak w kodzie jest?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Jak znam zycie to dales ten kod w sekcji head. I juz w tej sekcji probuje pobrac elementy ale one jeszcze nie istnieja.
wstaw
Kod
var div1=document.getElementById('first');
var div2=document.getElementById('second');
w srodek tych 2 funkcji.


--------------------
Go to the top of the page
+Quote Post
robos85
post
Post #3





Grupa: Zarejestrowani
Postów: 466
Pomógł: 11
Dołączył: 21.09.2006
Skąd: Szczecin

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


podziękować smile.gif
Go to the top of the page
+Quote Post
ikssde
post
Post #4





Grupa: Zarejestrowani
Postów: 217
Pomógł: 40
Dołączył: 20.08.2008

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


Nie deklaruj zmiennych poza cialem funkcji, przeciez mozna zrobic to owiele latwiej :

CODE

function show1(){

document.getElementById("first").style.display="block";
document.getElementById("second").style.display="none";
}
function show2(){
document.getElementById("first").style.display="none";
document.getElementById("second").style.display="block";
}


Sie spoznilem...

Ten post edytował ikssde 28.08.2008, 12:25:05
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 Aktualny czas: 20.08.2025 - 10:03