In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "JavaScript onclick how to click and switch pictures and automatically play". In daily operation, I believe many people have doubts about how to click and switch pictures and play them automatically in JavaScript onclick. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "how to click and switch pictures and automatically play pictures in JavaScript onclick". Next, please follow the editor to study!
Here is the complete code:
/ / add a click event to the four button and the next stop / / get the img var img = document.getElementById ("img"); / / set a variable to switch the picture as the index value var index = 0; / / set a variable to store the return value of the timer var t = null / / define an array of addresses for storing photos var imgPath = [. / img/0.webp ",". / img/1.webp ",". / img/2.webp ",". / img/3.webp ",". / img/4.webp ",". / img/5.webp ",". / img/6.webp ",". / img/7.webp " ". / img/8.webp"] / / next function changeImg () {/ / We use the ternary operator index = index > = (imgPath.length-1)? 0:++index Img.src = imgPath [index]; / / or if judgment / / if (index > = imgPath.length-1) {/ / index=0; / / img.src = `$ {imgPath [index]} `; / /} else {/ / index++ / / img.src = `${imgPath [index]}` / /} / / the previous function changeImg1 () {/ / same as above index= index 0 & & index
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.