Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente bannato
    Registrato dal
    Feb 2005
    Messaggi
    55

    onclick immagine random con testo non random senza refresh

    buonanotte

    codice:
    <script language="JavaScript">
    var rand1 = 0;
    var useRand = 0;
    
    images = new Array;
    images[1] = new Image();
    images[1].src = "1.png";
    images[2] = new Image();
    images[2].src = "2.png";
    images[3] = new Image();
    images[3].src = "3.png";
    images[4] = new Image();
    images[4].src = "4.png";
    
    function swapPic() {
    var imgnum = images.length - 1;
    do {
    var randnum = Math.random();
    rand1 = Math.round((imgnum - 1) * randnum) + 1;
    } while (rand1 == useRand);
    useRand = rand1;
    document.randimg.src = images[useRand].src;
    }
    </script>

    onLoad="swapPic()"

    onClick="swapPic();"


    Io ho questo script che mi sono cercato che stampa una immagine che cliccando cambia.
    Vorrei sempicemente aggiungere che, a seconda l'immagine random che appare,
    sotto l'immagine scriva anche un certo testo a seconda l'immagine che è comparsa
    (testo invisibile, anzi, semplicemente stesso colore dello sfondo, ma questo non è importante)

    Grazie se qualcuno mi aiuta non conosco javascript e ci ho passato ore a provare...

  2. #2
    Utente bannato
    Registrato dal
    Feb 2005
    Messaggi
    55
    codice:
    <script language="JavaScript">
    var rand1 = 0;
    var useRand = 0;
    
    images = new Array;
    images[1] = new Image();
    images[1].src = "1.png";
    images[2] = new Image();
    images[2].src = "2.png";
    images[3] = new Image();
    images[3].src = "3.png";
    images[4] = new Image();
    images[4].src = "4.png";
    
    function swapPic() {
    var imgnum = images.length - 1;
    do {
    var randnum = Math.random();
    rand1 = Math.round((imgnum - 1) * randnum) + 1;
    } while (rand1 == useRand);
    useRand = rand1;
    document.randimg.src = images[useRand].src;
    if (images[useRand].src==images[1].src) { document.write("testo sotto immagine 1");}
    }
    </script>


    sono arrivato soltanto a questo ma io vorrei che apparisse anche l'immagine

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.