博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
图片切换一
阅读量:4665 次
发布时间:2019-06-09

本文共 1844 字,大约阅读时间需要 6 分钟。

<!DOCTYPE html
>
<
html
lang=
"en"
>
<
head
>
<
meta
charset=
"UTF-8"
>
<
meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<
meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<
title
>图片切换
</
title
>
<
style
>
.box img {
width:
300px;
height:
300px;}
.box {
margin:
0
auto;
position:
relative;
width:
300px;}
.box input {
width:
70px;
font-size:
12px;
background-color:
#8E8E8E;
border:
none;
border-radius:
4px;
cursor:
pointer;
color:
white;}
.box #p {
width:
300px;
height:
30px;
line-height:
30px;
font-size:
16px;
color:
black;
background-color:
white;
opacity:
0.5;
position:
absolute;
bottom:
0;
top:
254px;
text-align:
center;}
form {
text-align:
center;}
.box #num {
text-align:
center;
font-size:
14px;
color:
gray;
margin-bottom:
5px;
margin-top:
5px;}
.box .btn1 {
margin-bottom:
10px;
margin-top:
10px;}
<
/
style
>
</
head
>
<
body
>
<
div
class=
"box"
>
<
img
src=
"img/1a.jpg"
id=
"pic"
>
<
p
id=
"num"
>1/5
</
p
>
<
form
>
<
input
type=
"button"
value=
"上一张"
id=
"forward"
>
<
input
type=
"button"
value=
"下一张"
id=
"next"
>             
</
form
>
<
p
id=
"p"
>这是第一张图片
</
p
>           
</
div
>
<
script
>
var
next=
document.
getElementById(
"next");
var
forward=
document.
getElementById(
"forward");     
var
pic=
document.
getElementById(
"pic");
var
num=
document.
getElementById(
"num");
var
p=
document.
getElementById(
"p");
var
arr=[
"img/1a.jpg",
"img/2.jpg",
"img/3.jpg",
"img/4.jpg",
"img/5.jpg"];
var
p1=[
"这是第一张图片",
"这是第二张图片",
"这是第三张图片",
"这是第四张图片",
"这是第五张图片"];
var
n=
0;
next.
onclick=
function(){
n++;
if(
n>
arr.
length-
1){
n=
0;
}
change();
};
forward.
onclick=
function(){
n--;
if(
n<
0){
n=
arr.
length-
1
}
change();
};
function
change(){
pic.
src=
arr[
n];
p.
innerHTML=
p1[
n];
num.
innerHTML=
n+
1 +
"/" +
arr.
length;
}
<
/
script
>
</
body
>
</
html
>

转载于:https://www.cnblogs.com/hilxj/p/10425405.html

你可能感兴趣的文章
codeforces666A
查看>>
比较真实的下雪效果
查看>>
MongoDB 3.2 从安装到使用。
查看>>
CFround#380 div2
查看>>
设计模式基础知识备忘
查看>>
中国国家气象局天气预报信息接口
查看>>
牛客寒假算法基础集训营2 处女座的砝码 (思维)
查看>>
Samba 3.5.10 发布
查看>>
ORACLE升级PSU&OJVM注意的问题及遇到问题解决思路
查看>>
框架篇:Spring+SpringMVC+hibernate整合开发
查看>>
Masonry教程--IOS自适配,丢掉Autolayout吧
查看>>
java调用.net的webservice接口
查看>>
wifi使用的一些误区
查看>>
跨页传值另一种方法
查看>>
最短路相关
查看>>
Java基础学习总结 -- 多线程的实现
查看>>
HTML5实现图片文件异步上传
查看>>
MyBatis 3模糊查询(like)写法(转)
查看>>
递归(字符串)遇到一个不懂的问题
查看>>
HDFS内容追加
查看>>