fai in questo modo:
codice:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento senza titolo</title> <script language="javascript"> function tabella_bicolore(){ //1. Raggruppiamo tutti i tag <tr> var righe= document.getElementsByTagName("tr") alert("Entra") for(i=0;i<righe.length;i++){ if((i+1)%2==0){ righe[i].style.backgroundColor="#009";} else{righe[i].style.backgroundColor="white";} } } </script> </head> <body> <table border="1" width="100%"> <tr><td>Ciao</td></tr> <tr><td>Ciao</td></tr> <tr><td>Ciao</td></tr> <tr><td>Ciao</td></tr> <tr><td>Ciao</td></tr> <tr><td>Ciao</td></tr> <tr><td>Ciao</td></tr> </table> <input type="button" onclick="tabella_bicolore();" Value="Cambia" /> </body> </html>

Rispondi quotando