<head>
<meta charset="UTF-8">
<title>2142013141</title>
<style>
#image {
display: block;
width: 500px;
height: 180px;
margin: 10px auto;
}
#next {
margin-left: 750px;
}
</style>
</head>
<body>
<img src="img/1.jpg" id="image"/>
<button id="next">next</button>
<button id="prev">prev</button>
<script>
Window.onload=function()
{
var image=document.getElementById("image");
var next=document.getElementById("next");
var prev=document.getElementById("prev");
var nowIndex=1;
var count=6;
next.onclick = function(){
nowIndex=nowIndex+1>count?1:nowIndex+1;
image.src="img/"+nowIndex+".jpg";}
prev.onclick = function(){
nowIndex = nowIndex<=1?count:nowIndex-1;
image.src="img/"+nowIndex+".jpg";}
}
</script>
</body>
想请问一下下面代码有哪里错了吗为什么切不了图
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
uliar 2022-02-28 14:43关注第22行的window的w要小写
Window.onload=function() => window.onload=function()
而且你script标签是在按钮和图片创建后执行的,window.onload事件完全可以删除
采纳一下哈
本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报 编辑记录解决 1无用