<!DOCTYPE?html>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>練習(xí)題</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時(shí)-3日8時(shí)降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月2日8時(shí)-3日8時(shí)全國(guó)降水量預(yù)報(bào)"},
{"src":"img/weather/2日8時(shí)-3日8時(shí)最低氣溫.jpg","href":"http://www.nmc.cn/publish/temperature/low.html","title":"3月2日8時(shí)-3日8時(shí)全國(guó)最低氣溫預(yù)報(bào)"},
{"src":"img/weather/3日8時(shí)-4日8時(shí)最高氣溫.jpg","href":"http://www.nmc.cn/publish/temperature/hight.html","title":"3月3日8時(shí)-3月4日8時(shí)全國(guó)最高氣溫預(yù)報(bào)"},
{"src":"img/weather/2日8時(shí)-3日8時(shí)短時(shí)強(qiáng)降水.png","href":"http://www.nmc.cn/publish/bulletin/index.html","title":"3月2日8時(shí)-3月3日8時(shí)全國(guó)短時(shí)強(qiáng)降水預(yù)報(bào)"},
{"src":"img/weather/3日8時(shí)-4日8時(shí)降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月3日8時(shí)-3月4日8時(shí)全國(guó)降水量預(yù)報(bào)"},
{"src":"img/weather/4日8時(shí)-5日8時(shí)降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月4日8時(shí)-3月5日8時(shí)全國(guó)降水量預(yù)報(bào)"}
]
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時(shí)-3日8時(shí)降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月2日8時(shí)-3日8時(shí)全國(guó)降水量預(yù)報(bào)"},
{"src":"img/weather/2日8時(shí)-3日8時(shí)最低氣溫.jpg","href":"http://www.nmc.cn/publish/temperature/low.html","title":"3月2日8時(shí)-3日8時(shí)全國(guó)最低氣溫預(yù)報(bào)"},
{"src":"img/weather/3日8時(shí)-4日8時(shí)最高氣溫.jpg","href":"http://www.nmc.cn/publish/temperature/hight.html","title":"3月3日8時(shí)-3月4日8時(shí)全國(guó)最高氣溫預(yù)報(bào)"},
{"src":"img/weather/2日8時(shí)-3日8時(shí)短時(shí)強(qiáng)降水.png","href":"http://www.nmc.cn/publish/bulletin/index.html","title":"3月2日8時(shí)-3月3日8時(shí)全國(guó)短時(shí)強(qiáng)降水預(yù)報(bào)"},
{"src":"img/weather/3日8時(shí)-4日8時(shí)降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月3日8時(shí)-3月4日8時(shí)全國(guó)降水量預(yù)報(bào)"},
{"src":"img/weather/4日8時(shí)-5日8時(shí)降水量.jpg","href":"http://www.nmc.cn/publish/precipitation/1-7day-precipitation.html","title":"3月4日8時(shí)-3月5日8時(shí)全國(guó)降水量預(yù)報(bào)"}
]
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>
為什么綁定事件沒(méi)有反應(yīng)呢,檢查好久了。真心求幫助
慕數(shù)據(jù)4485210
2016-03-03 20:30:36