[javascript] changer couleur dans plusieurs cellules

changer couleur dans plusieurs cellules [javascript] - HTML/CSS - Programmation

Marsh Posté le 19-08-2004 à 15:13:24    

lut
 
voila j ai cree plusieurs balise td  ou j ai coller le meme id et j ai rajoute un fonction OnMouseOver="chgColor(id,'ff00ff');"
 
comment doit etre la fonction chgColor pour mettre la couleur ff00ff dans toute mes cases ayant le meme id
 
c est 4 facon ne marche pas
 
function chgColor(rowNum,Color) {  
//document.all(rowNum).style.bgColor=Color;
//rowNum.style.BackGroundColor=Color
//rowNum.bgColor=Color
document.getElementById(id).style.backgroundColor=Color
}  
 
 
quelle est la bonne syntaxe
merci ++

Reply

Marsh Posté le 19-08-2004 à 15:13:24   

Reply

Marsh Posté le 19-08-2004 à 22:19:27    

Lut aussi ,
 
2 éléments d'une page ne peuvent avoir le même id
 

Code :
  1. <html>
  2. <head>
  3. <title>page web</title>
  4. </head>
  5. <body>
  6. <table border=1 id=monTable width=200 height=200 >
  7. <tr>
  8.        <td id=a1 onclick="colorTD(this.id)">&nbsp;a1</td>
  9.        <td id=a2 onclick="colorTD(this.id)">&nbsp;a2</td>
  10. </tr>
  11. <tr>
  12.        <td id=b1 onclick="colorTD(this.id)">&nbsp;b1</td>
  13.        <td id=b2 onclick="colorTD(this.id)">&nbsp;b2</td>
  14. </tr>
  15. <tr>
  16.        <td id=a3 onclick="colorTD(this.id)">&nbsp;a3</td>
  17.        <td id=b3 onclick="colorTD(this.id)">&nbsp;b3</td>
  18. </tr>
  19. </table>
  20. <script language="javascript">
  21. function colorTD(currentTD)
  22. {
  23. allTD = document.getElementById("monTable" ).getElementsByTagName("td" );
  24. for(i=0;i<allTD.length;i++)
  25.   if (allTD[i].id.substr(0,1)==currentTD.substr(0,1))
  26.        allTD[i].style.background = "#FF6600";
  27.   else
  28.        allTD[i].style.background = "#FFFFFF";
  29. }
  30. </script>
  31. </body>
  32. </html>


 
++
 
L

Reply

Marsh Posté le 24-08-2004 à 15:30:45    

thks
sous mozilla ok mais j ai la net impresion que ca macrhe pas sous Ie
qu est ce qu il marche pas et par koi remplacer

Reply

Marsh Posté le 24-08-2004 à 15:56:53    

:pfff:  
les CSS prévoient une magnifique pseudo classe "hover" et voila :cry:  
 
et mise en page à coup de tables en bonus [:benou_miam]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 24-08-2004 à 16:15:15    

j ai rien dit
lol
thks

Reply

Marsh Posté le 26-08-2004 à 18:43:31    

Masklinn : où as tu vu une mise en page à coup de tables ?
qui te dit qu'il n'a pas l'intention d'afficher des données tabulaires ?
l'utilisation des tables serait-t'elle interdite ?
serais-tu devin ?

Reply

Marsh Posté le 26-08-2004 à 20:53:33    

je parlais de ce que tu as commis pas de lui ^_^


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 27-08-2004 à 06:48:24    

ben , donne ta version au lieu de critiquer stupidement !!!

Reply

Marsh Posté le 27-08-2004 à 09:51:06    

D'accord pour les tableaux, si c'est justifié,
mais les &nbsp; n'ont rien à faire là.
 
Ma solution?
 
margin-left: 1em;
 
Voilà :)

Reply

Marsh Posté le 27-08-2004 à 10:29:03    

c'est déjà fait, CSS td:hover, ultra dur
 
je peux même préciser:

Code :
  1. td:hover {
  2.     background-color: #FF00FF;
  3. }


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 27-08-2004 à 10:29:03   

Reply

Marsh Posté le 27-08-2004 à 18:27:18    

ah ouais ....
t'a tout compris !
 
"pour mettre la couleur ff00ff dans toutes mes cases ayant le meme id " et non uniquement DANS LA CASE SURVOLEE !
 
et hover ne fonctionne pas sous I.E (+ de 80% des internautes !)
BRAVO !

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed