Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1849 connectés 

  FORUM HardWare.fr
  Programmation
  HTML/CSS

  [Javascript] comment remplacer une image ouverte???

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Javascript] comment remplacer une image ouverte???

n°1494125
mjcom
le savoir est universel
Posté le 20-12-2006 à 13:02:20  profilanswer
 

Salut!
Quand j'execute mon script et je clic sur un lien, mon graphique s'affiche, mais je veux afficher un autre graphe quand je clic sur un autre lien. Le probleme c'est que je ne veux pas le nouveau graphique à coté de l'ancien mais à la place de celui-ci. Donc quand je clic sur un lien le nouveau graphe doit remplacer l'autre.
Merci. J'espere avoir été clair.

Code :
  1. // JavaScript Document
  2. function graph_france(chart)
  3. {
  4. var graph = document.getElementById(chart);
  5. if(chart == "cac_graph" && graph.innerHTML == "" )
  6.  {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;'alt='Chart CAC 40' /></div>";}
  7.  else if(chart == "cacnext20_graph" && graph.innerHTML == "" )
  8.    {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart CACNEXT 20'/></div>"; }
  9.   else if(chart == "itcac_graph" && graph.innerHTML == "" )
  10.     {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart ITCAC 50'/></div>";} 
  11.    else if(chart == "sbf80_graph" && graph.innerHTML == "" )
  12.      {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart SBF 80'/></div>";}
  13.     else if(chart == "sbf120_graph" && graph.innerHTML == "" )
  14.       {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;'alt='Chart SBF 120' /></div>";}
  15.      else if(chart == "sbf250_graph" && graph.innerHTML == "" )
  16.        {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart SBF 250'/></div>";}
  17.       else if(chart == "mid_graph" && graph.innerHTML == "" )
  18.         {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart MIDCAPS'/></div>";}
  19.        else if(chart == "small_graph" && graph.innerHTML == "" )
  20.     {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart SMALLCAPS'/></div>";}
  21.         else if(chart == "alternext_graph" && graph.innerHTML == "" )
  22.           {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart ALTERNEXT'/></div>";}
  23.          else if(chart == "vix1_graph" && graph.innerHTML == "" )
  24.            {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart VIX1'/></div>";}
  25.           else if(chart == "vix6_graph" && graph.innerHTML == "" )
  26.             {graph.innerHTML = "<div><img  src='http://fr.ichart.yahoo.com/t?s=^FCHI' width='200' height='120' style='border-color:#368EBE; border:1px solid;' alt='Chart VIX6'/></div>";}
  27. else graph.innerHTML = "";
  28. }


et dans ma page j'ai mis un <span id=".."></span>

Code :
  1. <tr onmouseover="this.className='sur'" onmouseout="this.className='hors'">
  2.     <td><a href="javascript:graph_france('cac_graph')" class="graph">CAC 40</a></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
  3.    </tr>
  4. ....
  5. <table align="center" cellspacing="0">
  6. <tr>
  7. <td><span id="cac_graph"></span></td><td><span id="cacnext20_graph"></span></td>
  8. <td><span id="itcac_graph"></span></td><td><span id="sbf80_graph"></span></td>
  9. <td><span id="sbf120_graph"></span></td><td><span id="sbf250_graph"></span></td>
  10. <td><span id="mid_graph"></span></td><td><span id="small_graph"></span></td>
  11. <td><span id="alternext_graph"></span></td><td><span id="vix1_graph"></span></td>
  12. <td><span id="vix6_graph"></span></td>
  13. </tr>
  14. </table>


Message édité par mjcom le 20-12-2006 à 14:52:44

---------------
[:bossik]
mood
Publicité
Posté le 20-12-2006 à 13:02:20  profilanswer
 

n°1494131
FlorentG
Unité de Masse
Posté le 20-12-2006 à 13:14:40  profilanswer
 

Oh mon dieu

n°1494150
mjcom
le savoir est universel
Posté le 20-12-2006 à 13:37:03  profilanswer
 

et oui je suis un zero en JS


---------------
[:bossik]
n°1495169
bixibu
Ca ... c'est fait!
Posté le 22-12-2006 à 07:27:54  profilanswer
 

Oula oula, bon dans l`ordre :
 
pour changer la source d`une image :

Code :
  1. <img id='mon_image' src='toto.jpg' />
  2. <a onclick="document.getElementById('mon_image').src = 'images/llimagequetuveux.jpg'; ">


il ya d`autre methode pour par exemple, precharger les autre images mais je te laisse chercher sur google.
 
Ensuite, au lieu de faire suivre 20000 elseif, il ya une forme algorythmique toute faite pour ce genre d`utilisation.. :
(mais tu pourrais tout aussi bien utiliser un tableau associatif ou c`que tu veux)

Code :
  1. var new_img;
  2. switch (chart)
  3. {
  4.   case 'cac_graph':
  5.      new_img ='img1.jpg'
  6.    break;
  7.    case 'cacnext20_graph':
  8.      new_img ='img2.jpg'
  9.    break;
  10.    ... ect ...
  11.   default:
  12.       //Instruction_par_défaut  
  13.       img_new = '';
  14.    break;
  15. }
  16. //puis le truc d`au dessus :
  17. document.getElementById('mon_image').src = new_img;


 
Appliques ca, tu devrais y arriver

n°1495218
mjcom
le savoir est universel
Posté le 22-12-2006 à 10:58:14  profilanswer
 

merci bcp!!!


---------------
[:bossik]

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  HTML/CSS

  [Javascript] comment remplacer une image ouverte???

 

Sujets relatifs
javascript Greasemonkey : problème de perfo ?javascript et ie 7
Resize d'image[Javascript] Formulaire dans formulaire accessible ?
[Javascript] la fonction charAt(); [résolu]Problème de soumission d'un formulaire par une image
[Javascript] Question de noob sur les evenements (premier code JavascrJavascript: retrouver la méthode d'envoi de paramètres
Image map à choix multipleTexte dynamique sur image
Plus de sujets relatifs à : [Javascript] comment remplacer une image ouverte???


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR