为什么绑定事件没有反应呢,检查好久了。真心求帮助

<!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>


慕数据4485210
浏览 1628回答 2
2回答

蛋白

showPic定义了没有调用,onclick调用next(),next()中的index没有定义,var num = index.num报错,你每次next()调用也要num++才对.

慕数据4485210

忽然发现,这样做的结果是num只是取到了一个值,页面只会翻动一下。怎么才能连续翻动刷新num的值呢。。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript