Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482

    Cambiare attributo style

    Premetto che smanetto con javascript per la prima volta

    Ho questo codice:

    codice:
    <html> 
    <head> 
    <title>Shopping for Neckties at the Kiwi Republic</title> 
    <script Language="JavaScript">
    function MyShow(IntMN)
    {
    TD1.style("background-color") = "#ffcc00";
    }
    </script> 
    </head>
    <body ID="Body1"> 
    <table Width="100%">
    <tr>
    		<td ID="TD1" OnMouseOver="MyShow(1)"
    		OnMouseOut="TD1.bgColor='#FFFFFF'">Link1</td>
           <td ID="TD2" onMouseOver="TD2.bgColor='#FFCC00'" OnMouseOut="TD2.bgColor='#FFFFFF'">Link2</td>
           <td ID="TD3" onMouseOver="TD3.bgColor='#FFCC00'" OnMouseOut="TD3.bgColor='#FFFFFF'">Link3</td>
           <td ID="TD4" onMouseOver="TD4.bgColor='#FFCC00'" OnMouseOut="TD4.bgColor='#FFFFFF'">Link4</td>
           <td ID="TD5" onMouseOver="TD5.bgColor='#FFCC00'" OnMouseOut="TD5.bgColor='#FFFFFF'">Link5</td>
    </tr>
    </table>
    <Div ID="Div1" Style="Visibility:Hidden">
    Bla
    
    Bla
    
    Bla
    <Div>
    </body> 
    </html>
    Così come'è non funziona, invece se al posto di:

    TD1.style("background-color") = "#ffcc00";

    Scrivo:

    TD1.bgColor = "#ffcc00";

    Tutto funziona.
    Il problema è che io devo poter rendere visibile o invisibile il tag Div chiamato Div1, e devo poter scrivere:

    Div1.style("visibility") = "hidden";

    Hey hey, my my Rock and roll can never die!

  2. #2
    Dovrebbe essere così
    document.getElementById('Div1').style.visibility ="hidden";

    document.getElementById('Div1').style.visibility ="visible";
    La più grande forza a disposizione dell'umanità è la non violenza (Ghandi).
    (15/06/2003 - 16 points, 17 rembounds and 1 standing ovation x Admiral David Robinson ... San Antonio Spurs~ 2003/5 NBA champions)

  3. #3
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    se non vuoi usare bgcolor (ho il dubbio che non sia consigliato dal w3c),
    style="background-color:#ff0000"
    diventa
    document.getElementById('id_elemento').style.backg roundColor='#ff0000'

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482
    Grazie mille!

    Un'altra domanda, sempre con lo stesso codice:

    codice:
    <script Language="JavaScript">
    function MyShow(IntMN)
    {
    TD1.style("background-color") = "#ffcc00";
    }
    </script> 
    ...
    <td ID="TD1" OnMouseOver="MyShow(1)"
    OnMouseOut="TD1.bgColor='#FFFFFF'">Link1</td>
    ...
    Ora come vedete io richiamo la funzione MyShow e gli passo come parametro "1"
    Se io passassi come parametro 2 come faccio a dire alla funzione di eseguire le operazioni su TD2 invece che su TD1?

    Hey hey, my my Rock and roll can never die!

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482
    codice:
    document.getElementById('Div' + IntMN).style.visibility ="hidden";
    Scusate...

    Hey hey, my my Rock and roll can never die!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.