This time I will bring you JS click to cycle to switch to play pictures , what are the precautions for JS to click to cycle to switch to play pictures, the following is a practical case, let's take a look take a look.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>单击循环切换图片</title> <script> var i = 1; function nextImg(){ i++; //步骤2:获取页面元素 var next = document.getElementById("nImg"); //步骤3:更改元素的src属性 next.src = "img/"+i+".jpg"; if(i==3){ i=0; } } </script> </head> <body> <p> <!--步骤1:绑定onclick事件--> <button onclick="nextImg()">下一张</button> <br /> <!--需自己准备3张图片--> <img src="img/1.jpg" id="nImg" width="600px" height="400px" /> </p> </body> </html>
Recommended reading:
Use js to implement intra-page jumpJS to implement multiple choice assessment systemThe above is the detailed content of JS click cycle to switch to play pictures. For more information, please follow other related articles on the PHP Chinese website!