Newsgroup: it.comp.lang.javascript
Titolo: Utilizzo Layer

Come faccio a visualizzare due layer diversi in funzione del collegamento
che premo?
Cioč se vado su un collegamento detto testo, questo deve visualizzarmi per
esempio un immagine, mentre se premo il collegamento Appunti si dovrebbe
vedere un immagine diversa che vada a ricoprire la precedente
spero di essere stato chiaro, grazie
Davide
Io ho scritto questo ma non mi si sovrappongono i layer come mai?!?
<script>
<!--
function reveal (num) {
  if (num == 1){
      document.layers.lr01.visibility="show";
  }else{
      document.layers.lr01.visibility="hide";
  }
  if (num == 2){
      document.layers.lr02.visibility="show";
  }else{
      document.layers.lr02.visibility="hide";
  }
// -->
</script>
</head>
....
<layer name="lr01" visibility="show">
This person, although posing as a farm worker, is about
to be apprehended by her local police department for theft
of agricultural products. Questionable sources report this
as yet another case of petal pushing, driven by demand for
parade floats built for college football bowl games.
</layer>
....
<layer name="lr02" visibility="hide">
These giant flowers, often growing larger than a two-story
house, were frequently used as cover by soldiers
in the European theater of both world wars. Unfortunately,
enemy forces firing into the large centers released huge
clouds of pollen that forced the hidden troops into
tremendous fits of sneezing, and thus into revealing their
positions.
</layer>
<ilayer height="200">
</ilayer>

 Davide
<html>
<head>
<title>test</title>
<script>
function reveal (num) {
  if (num == 1){
      document.layers.lr01.visibility="show";
      document.layers.lr02.visibility="hide";
  }
  else if (num == 2){
      document.layers.lr02.visibility="show";
      document.layers.lr01.visibility="hide"
  }
}
</script>
</head>
<body>
<div id="lr01" style="position:absolute;visibility:show;">
This person, although posing as a farm worker, is about
to be apprehended by her local police department for theft
of agricultural products. Questionable sources report this
as yet another case of petal pushing, driven by demand for
parade floats built for college football bowl games.
</div>
....
<div id="lr02" style="position:absolute;visibility:hide">
These giant flowers, often growing larger than a two-story
house, were frequently used as cover by soldiers
in the European theater of both world wars. Unfortunately,
enemy forces firing into the large centers released huge
clouds of pollen that forced the hidden troops into
tremendous fits of sneezing, and thus into revealing their
positions.
</div>
<p>&nbsp;</p>
<p><a
href="javascript:reveal(2);">mostra2</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="javascript:reveal(1);">mostra1</a></p>
</body>
</html>
andreotta fabiano
 WebMŞster ATI POWER s.n.c.
 
andr...@atipower.it
 
http://www.atipower.it
 
http://www.aticommerce.com
 
http://www.afdsoftware.freeweb.org
 
http://www.jsdir.com
 
http://www.javascript.3000.it

 ha scritto nel messaggio
news:90rhgi$215dl$1...@ID-57211.news.dfncis.de...


   }
il problema e' qui !! Il costrutto if-then-else e' concettualmente
sbagliato:
se e' come credo ( solo 2 possibili valori della variabile num) allora
scrvi:
if  (num == 1)
{
  document.layers.lr01.visibility="show";
  document.layers.lr02.visibility="hide";
}
else
{
  document.layers.lr02.visibility="show";
  document.layers.lr01.visibility="hide";
}
In alternativa puoi usare il costrutto switch-case:
switch(num)
{
    case 1:   document.layers.lr01.visibility="show";
                 document.layers.lr02.visibility="hide";
                 break;
    case 2:   document.layers.lr02.visibility="show";
                 document.layers.lr01.visibility="hide";
                 break;
}
che forse e' piu' leggibile.
Templar