
大家好,又见面了,我是你们的朋友全栈君。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>照片点击切换</title>
</head>
<style>
*{
margin:0;
padding:0;
}
#picBox{
margin:100px auto;
width:600px;
height:400px;
}
#pic{
width:600px;
height:400px;
}
#buttonBox{
width:150px;
margin:10px auto;
}
</style>
<body>
<div id="picBox">
<img src="1.jpg" id="pic">
<div id="buttonBox">
<input type="button" value="上一张" onclick="pre();">
<input type="button" value="下一张" onclick="next();">
</div>
</div>
<script>
var picArr=new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg");
var index=0;
function next(){
index++;
if(index==picArr.length){
index=0;
}
document.getElementById("pic").src=picArr[index];
}
function pre(){
index--;
if(index<0){
index=picArr.length-1;
}
document.getElementById("pic").src=picArr[index];
}
</script>
</body>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/213396.html原文链接:https://javaforall.cn