April 24
Il Document Object Model (DOM) offre ai progettisti Web Access per la struttura nascosta di una pagina Web. I metodi JavaScript getElementById, getElementsByTagName, getElementsByClassName, getElementsByTagName, createElement e createAttribute possono verificare, modificare e aggiungere i tag HTML e informazioni styling. Il "innerHTML" proprietà della funzione getElementById permette di contenuti da inserire tra gli elementi HTML come intestazioni, paragrafi, link e elenchi ordinati. elementi HTML devono essere etichettati con un ID o il nome o JavaScript non possano accedervi.
1 Avviare il, testo semplice editor di testo standard che è disponibile sul computer.
2 Inserire il codice seguente nel editor di testo.
<Html>
<Head>
<Style type = "text / css">
p {
font-weight: normal;
colore rosso;
font-style: normal;
font-size: 2em;
border: 1px nero punteggiato;
background-color: yellow;
width: 50%;
}
</ Style>
<Script language = "javascript">
Funzione changeStyle () {
. Document.getElementById ( "test") fontWeight = "bold";
. Document.getElementById ( "test") style.color = "bianco";
document.getElementById ( "test") style.fontStyle = "italic".;
. Document.getElementById ( "test") style.fontSize = "4em";
. Document.getElementById ( "test") style.backgroundColor = "nero";
. Document.getElementById ( "test") style.textAlign = "center";
. Document.getElementById ( "test") innerHTML = "JavaScript e DOM rock !!";
. Document.getElementById ( "contenitore") style.backgroundColor = "giallo";
}
</ Script>
</ Head>
<Body id = "container">
<P id = "test" onClick = "javascript: changeStyle ()">. Clicca qui per cambiare pagina styling </ p>
</ Body>
</ Html>
3 Fare clic sul menu "File". Selezionare l'opzione "Salva". Salvare sotto il nome del file "test.html."
4 Avviare il browser Web che è disponibile sul computer. Fare clic sulla voce di menu "File" e selezionare "Apri file".
5 Individuare il file "test.html" appena creata, selezionare con il mouse, quindi fare clic su "Apri".
6 Fare clic sul testo con lo sfondo giallo per cambiare l'aspetto della pagina.