Generalnie napisałem sobie funkcję zmieniania zawartości div'a, tzn. nie zamieniania zawartości, a przełączenia divów. Jestem zupełnie początkujący w js, i napisanie tego mi trochę zajęło, ale się czegoś nauczyłem ;] Zastanawiam się tylko, czy ta funkcja jest w miarę poprawnie napisana? I też, do czego służy to "return false;" w onclick=""?
<script type="text/javascript"><!-- function changeBox(name) {
switch (name)
{
case 'forum':
document.getElementById('forum').style.display='';
document.getElementById('sonda').style.display='none';
document.getElementById('foto').style.display='none';
break
case 'sonda':
document.getElementById('forum').style.display='none';
document.getElementById('sonda').style.display='';
document.getElementById('foto').style.display='none';
break
case 'foto':
document.getElementById('forum').style.display='none';
document.getElementById('sonda').style.display='none';
document.getElementById('foto').style.display='';
break
}
}
//-->
<a href="#" onclick="changeBox('forum'); return false;">a
</a><br> <a href="#" onclick="changeBox('sonda'); return false;">b
</a><br> <a href="#" onclick="changeBox('foto'); return false;">c
</a><br>
<div id="forum" style="display: none;">aaaaaaaa
</div> <div id="sonda" style="display: none;">bbbaabbbbb
</div> <div id="foto" style="display: none;">cccccccc
</div>
Pozdrawiam ;]