gpt4 book ai didi

javascript - 创建手动幻灯片时出错

转载 作者:太空宇宙 更新时间:2023-11-04 15:57:17 25 4
gpt4 key购买 nike

出于某种原因,我在我的 javascript 文件中的一行中不断收到以下错误(我在下面指出了该行)。这是我的 HTML:

<div class="slideshowproject">
<button id="rightbutton" onclick=manualslideshow("rightbutton,projectslides1")>></button>
<img class="projectslides1" src="Project Images\\HarrisonHealthClinic\\Render 1-1.jpg">
<img class="projectslides1" src="Project Images\\HarrisonHealthClinic\\Render 2-1.jpg">
<img class="projectslides1" src="Project Images\\HarrisonHealthClinic\\Render 3-1.jpg">
<button id="leftbutton" onclick=manualslideshow("leftbutton","projectslides1")><</button>
<script>manualslideshow("","projectslides1")</script>
</div>

和我的javascript:

var imagenumber=0;
function manualslideshow(buttonid,slideshowclass){
var pictures=document.getElementsByClassName(slideshowclass);
for (i=0;i<pictures.length;i++){
pictures[i].style.display="none";
}
if (buttonid=="rightbutton"){
imagenumber++;
}
else if (buttonid=="leftbutton"){
imagenumber--;
}
if (imagenumber>pictures.length){
imagenumber=1;
}
if (imagenumber<1){
imagenumber=pictures.length;
}
pictures[imagenumber-1].style.display="block";
}

出于某种原因,“.style.display="block";"在脚本的最后一行出现错误:

navigationbar.js:68 Uncaught TypeError: Cannot read property 'style' of undefined
at manualslideshow (navigationbar.js:68)
at HTMLButtonElement.onclick (clinic.html:42)

Javascript 第 68 行是最终闭合花括号之前的最后一行,html 中的第 42 行是“右键”行(复制过来的 HTML 中的第 2 行)

感谢您的所有帮助和时间。

最佳答案

查看您的代码,我发现从 Html 文件调用“manualslideshow”方法时出错。 (即第 42 行)。请看下面的代码。我已经从("rightbutton,projectslides1")("rightbutton","projectslides1")

<div class="slideshowproject">
<button id="rightbutton" onclick=manualslideshow("rightbutton","projectslides1")>></button>
<img class="projectslides1" src="Project Images\\HarrisonHealthClinic\\Render 1-1.jpg">
<img class="projectslides1" src="Project Images\\HarrisonHealthClinic\\Render 2-1.jpg">
<img class="projectslides1" src="Project Images\\HarrisonHealthClinic\\Render 3-1.jpg">
<button id="leftbutton" onclick=manualslideshow("leftbutton","projectslides1")><</button>
<script>manualslideshow("","projectslides1")</script>
</div>

关于javascript - 创建手动幻灯片时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44644623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com