参考网上做的轮播图片javascript,为何不起作用?
程序代码:
<!DOCTYPE html> <html> <head><title>Javascript Window</title></head> <body onload="init()"> <img id="pic" src="2.jpg" width="500" height="300" /><br /> <input type="button" value="1" onmouseover="onMouseHover(this)" /> <input type="button" value="2" onmouseover="onMouseHover(this)" /> <input type="button" value="3" onmouseover="onMouseHover(this)" /> <script type="text/javascript"> var arrImage=new array("1.jpg","2.jpg","3.jpg"); var Timer=self.setInterval("play()",1000); var count=0; function play() { if(arrImage.length==count) count=0; document.getElementById("pic").src=arrImage[count]; count++; } function clearTimer() { window.clearInterval(Timer); } function onMouseHover(obj) { clearTimer(); var index=parseInt(obj.value); document.getElementById("pic").src=arrImage[index-1]; count=index; } function onMouseLeave() { Timer=self.setInterval("play()",1000); } function init() { var btns=document.getElementByTagName("input"); for(var i=0;i<btns.length;i++) { btns[i].onmouseout=onMouseLeave; } } </script> </body> </html>
[此贴子已经被作者于2016-1-29 23:22编辑过]