<!doctype html><html> <head> <meta charset="UTF-8"> <style type="text/css">*{margin:0; padding:0;}#banner{width:730px; height:454px; margin:20px auto;position:relative; }#pic{width:730px; height:454px;}#pic img{position:absolute; top:0; left:0; display:none;}#left,#right{width:30px; height:40px; position:absolute; top:50%; margin-top:-20px;}#left{left:0px;}#right{right:0px;}#tab{width:160px; height:20px; position:absolute; left:50%; margin-left:-78px; bottom:10px;}#tab ul li{width:20px; height:20px; background:#bbb; color:#fff; text-align:center; line-height:20px; border-radius:100%; font-size:12px; font-family:"Microsoft yahei"; list-style:none; float:left; margin:0 3px; cursor:pointer;}#tab ul li.on{background:#f60;} </style> <title>定时轮播</title> </head> <body><div id="banner"><div id="pic"><img src="img/1.jpg" alt="" /><img src="img/2.jpg" alt="" /><img src="img/3.jpg" alt="" /><img src="img/4.jpg" alt="" /><img src="img/5.jpg" alt="" /><img src="img/6.jpg" alt="" /></div><div id="btn"><button id="left"><</button><button id="right">></button></div><div id="tab"><ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li></ul></div></div><script type="text/javascript">var aImg=document.getElementById("pic").getElementsByTagName("img");var aTabli=document.getElementById("tab").getElementsByTagName("li");aImg[0].style.display="block";aTabli[3].className="on";for(var i=0;i<aTabli.length;i++;){aTabli[i].onclick=function(){for(var j=0;j<aTabli.length;j++;){aTabli[j].className="";}this.className="on";};}</script> </body></html>
2 回答
已采纳
李晓健
TA贡献1036条经验 获得超461个赞
//下面一行括号最后多一个分号 for(var i=0;i<aTabli.length;i++){ aTabli[i].onclick=function(){ //下面一行括号最后多一个分号 for(var j=0;j<aTabli.length;j++){ console.log(aTabli[j]); aTabli[j].className=""; } this.className="on"; }; }
多了两个分号,所有就是语法错误,代码没有执行。
添加回答
举报
0/150
提交
取消