This article describes the method of randomly changing pictures by clicking on images by js mouse. Share it for your reference. The specific implementation method is as follows:
<html><title>Click the image with the mouse to randomly transform the image</title><body bgcolor="#fef4d9" OnLoad="swapPic()"><center><SCRIPT LANGUAGE="JavaScript"><!-- Beginvar rand1 = 0;var useRand = 0;images = new Array;images[1] = new Image();images[1].src = "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 --></script><a onClick="swapPic();"><img name="randimg" src="images/m09.jpg"></a><br><font face="Verdana" size="-2">click image to change</center></body></html>I hope this article will be helpful to everyone's JavaScript programming.