Cet article décrit la méthode de modification aléatoire des images en cliquant sur des images de JS Mouse. Partagez-le pour votre référence. La méthode de mise en œuvre spécifique est la suivante:
<html> <itle> Cliquez sur l'image avec la souris pour transformer aléatoirement l'image </Title> <Body bgColor = "# fef4d9" onload = "swappic ()"> <enter> <script linguisse = "javascrip "images/m01.jpg";images[2] = new Image();images[2].src = "images/m02.jpg";images[3] = new Image();images[3].src = "images/m03.jpg";images[4] = new Image();images[4].src = "images/m04.jpg";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;} // end -> </cript> <a on on onclick = "swappic ();); name = "randimg" src = "images / m09.jpg"> </a> <br> <font face = "Verdana" size = "- 2"> Cliquez sur l'image pour modifier </senter> </body> </html>J'espère que cet article sera utile à la programmation JavaScript de tous.