我有一個網站頁面和圖片幻燈片:<div className="recommended" id="bluelakes"> <p className="greeting-text">We also recommend you visiting <span>Blue Lakes</span>:</p> <div className="recommended-brief"> <div className="description"> <p> <span className="dark">Ecological trail "<span>Blue Lakes</span>"</span> <br/> <br/> is located on the territory of the Narochansky National Park in the Myadel district, 500 m beyond the village of Olshevo. <br/> <br/> Each time you come to this amazing place, you will discover something new, this is a unique hilly-lake complex with vast forests, an abundance of springs and truly unique lakes. </p> </div> <div className="carousel"> <div className="carousel-item first"> <img id="slide" alt="slide"/> </div> </div> <div className="more"> <a href="/" className="see-more">See more...</a> </div> </div></div>它看起來像這樣:這是幻燈片腳本本身:import bluelakesFirst from '../media/images/BlueLakes/BlueLakes1.jpg'import bluelakesSecond from '../media/images/BlueLakes/BlueLakes2.jpg'import bluelakesThird from '../media/images/BlueLakes/BlueLakes3.jpg'import bluelakesFourth from '../media/images/BlueLakes/BlueLakes4.jpg'let n = 0;let images = [];images[0] = bluelakesFirstimages[1] = bluelakesSecondimages[2] = bluelakesThirdimages[3] = bluelakesFourthlet switchImage = () => { document.getElementById('slide').src = images[n] if (n < images.length - 1) { n++; } else { n = 0; } setTimeout(switchImage, 3000);}window.onload = switchImage我理解這可能是因為其他頁面沒有帶有此 ID 的元素,但我也沒有在其他頁面上導入此腳本。
我的主頁上有一個圖片幻燈片,但是當我轉到其他頁面時它會引發錯誤
冉冉說
2023-03-18 11:02:17