<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>练习题</title>
</head>
<body>
<img src="#" id="pic">
<button id="next" onclick="next()">next</button>
<p id="description">description</p>
<script>
function showPic(){
var Pic = document.getElementById("pic");
var num = null;
var text = document.getElementById("description");
var next = document.getElementById("next");
var list = new Object();
var list = [
{"src":"img/weather/2日8时-3日8时降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月2日8时-3日8时全国降水量预报"},
{"src":"img/weather/2日8时-3日8时最低气温.jpg","href":"http://www.nmc.cn/publish/temperature/low.html","title":"3月2日8时-3日8时全国最低气温预报"},
{"src":"img/weather/3日8时-4日8时最高气温.jpg","href":"http://www.nmc.cn/publish/temperature/hight.html","title":"3月3日8时-3月4日8时全国最高气温预报"},
{"src":"img/weather/2日8时-3日8时短时强降水.png","href":"http://www.nmc.cn/publish/bulletin/index.html","title":"3月2日8时-3月3日8时全国短时强降水预报"},
{"src":"img/weather/3日8时-4日8时降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月3日8时-3月4日8时全国降水量预报"},
{"src":"img/weather/4日8时-5日8时降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月4日8时-3月5日8时全国降水量预报"}
]
function turnPic(){
if(num == list.length-1){
num = 0;
Pic.setAttribute("src",list[0].src);
Pic.setAttribute("title",list[0].title);
text.innerHTML = list[0].title;
}
else{
num+=1;
}
Pic.setAttribute("src",list[num].src);
Pic.setAttribute("title",list[num].title);
text.innerHTML = list[num].title;
Pic.timer = setTimeout(arguments.callee,5000);
index = {};
index.num = num;
}
turnPic();
}
function next(){
var Pic = document.getElementById("pic");
var src = Pic.getAttribute("src");
var text = document.getElementById("description");
var list = [
{"src":"img/weather/2日8时-3日8时降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月2日8时-3日8时全国降水量预报"},
{"src":"img/weather/2日8时-3日8时最低气温.jpg","href":"http://www.nmc.cn/publish/temperature/low.html","title":"3月2日8时-3日8时全国最低气温预报"},
{"src":"img/weather/3日8时-4日8时最高气温.jpg","href":"http://www.nmc.cn/publish/temperature/hight.html","title":"3月3日8时-3月4日8时全国最高气温预报"},
{"src":"img/weather/2日8时-3日8时短时强降水.png","href":"http://www.nmc.cn/publish/bulletin/index.html","title":"3月2日8时-3月3日8时全国短时强降水预报"},
{"src":"img/weather/3日8时-4日8时降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月3日8时-3月4日8时全国降水量预报"},
{"src":"img/weather/4日8时-5日8时降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月4日8时-3月5日8时全国降水量预报"}
]
var num =index.num;
Pic.setAttribute("src",list[num+1].src);
Pic.setAttribute("title",list[num+1].title);
text.innerHTML = list[num+1].title;
if(num == 5){
Pic.setAttribute("src",list[0].src);
Pic.setAttribute("title",list[0].title);
text.innerHTML = list[0].title;
}
}
</script>
</body>
</html>
2 回答
蛋白
TA贡献3条经验 获得超0个赞
showPic定义了没有调用,onclick调用next(),next()中的index没有定义,var num = index.num报错,你每次next()调用也要num++才对.
添加回答
举报
0/150
提交
取消