If und switch verschachteln?
Bastian T.
- javascript
0 MudGuard0 Bastian T.0 lars
0 Danny0 Struppi
Für eine Menüsteuerung habe ich fogendes Skript zusammengeschustert.
Muss dabei ziemlich viele Fälle abfragen und irgendwie scheitert es an der Stelle nach der ersten If-Abfrage. Browser sagt mir in Zeile 3 würde ein ; fehlen ?????????
Hier das Skript:
function init_move(wlayer){
If (ams==wlayer){
switch (wlayer){
case "top1":
move ('bottom1',125,25);
move ('top2',225,125);
move ('top3',250,150);
ams="";
break;
case "top2":
move ('bottom2',150,50);
move ('top3',250,150);
ams="";
break;
case "top3":
move ('bottom3',175,75);
ams="";
break;
}
}
else
{
switch (wlayer){
case "top1":
document.all.bottom1.style.zIndex = "3";
document.all.bottom2.style.zIndex = "2";
document.all.bottom3.style.zIndex = "1";
hide(bottom2);
hide(bottom1);
move ('top3',150,250);
move ('top2',125,225);
move ('bottom1',25,125);
ams="top1";
break;
case "top2":
document.all.bottom1.style.zIndex = "2";
document.all.bottom2.style.zIndex = "3";
document.all.bottom3.style.zIndex = "1";
hide(bottom2);
hide(bottom1);
move ('top3',150,250);
move ('bottom2',50,150);
ams="top2";
break;
case "top3":
document.all.bottom1.style.zIndex = "1";
document.all.bottom2.style.zIndex = "2";
document.all.bottom3.style.zIndex = "3";
hide(bottom2);
hide(bottom1);
move ('bottom3',75,175);
ams="top3";
break;
}
}
Noch was zu den Variablen: ams ist ein string, genauso wie wlayer und werden ausserhalb als globale Variable (zu Beginn leer) deklariert.
Schönen Dank für die Hilfe
Bastian
Hi,
function init_move(wlayer){
If (ams==wlayer){
If ist nicht if...
Ach ja, Einrückungen wären nicht schlecht...
cu,
Andreas
Schönen Dank.
Mal wieder nicht mit Ruhm bekleckert.
bdt
Bastian
will auch noch meinen senf abgeben:
switch (wlayer){
case "top1":
move ('bottom1',125,25);
move ('top2',225,125);
move ('top3',250,150);
ams="";
break;
(...)
}
...da fehlen noch klammern "()" und "{}":
switch (){
case ():{
}
}
gruß lars
Hallo Bastian,
Dir ist aber schon klar, dass es so (document.all) nur im IE funktioniert... ?
Gruß,
Danny
Für eine Menüsteuerung habe ich fogendes Skript zusammengeschustert.
So kann man das sagen.
Muss dabei ziemlich viele Fälle abfragen und irgendwie scheitert es an der Stelle nach der ersten If-Abfrage. Browser sagt mir in Zeile 3 würde ein ; fehlen ?????????
Hier das Skript:
function init_move(wlayer){
If (ams==wlayer){
'If' ist falsch!!
document.all.bottom1.style.zIndex = "3";
document.all.bottom2.style.zIndex = "2";
document.all.bottom3.style.zIndex = "1";
Dieses Skript hast du für den IE 4.x geschrieben? Der wird aber kaum noch irgendwo benutzt.
Informier dich doch mal über dHTML und wie man Layer in den verschiedenen Browsern anspricht.
Struppi.