您的位置:首页 > Web前端 > JavaScript

js实现图片切换

2009-10-23 22:13 225 查看
JScript code<style type="text/css">
div{
margin-top:10px;
}</style><script type="text/jscript">var i=1;var t=null;function doImage(i){if(i>6){
clearInterval(t);return;
};var mainDiv= document.getElementById('MainDiv');var img= document.createElement('img');
img.src=""+ i+".jpg";
img.height=50;
img.width=100;var div= document.getElementById('div'+ i);
div.appendChild(img);
img.onclick=function(){var mainDiv= document.getElementById('MainDiv');
mainDiv.firstChild.src=this.src;
}
mainDiv.firstChild.src= img.src;
}
window.onload=function(){var mainDiv= document.getElementById('MainDiv');var image= document.createElement('img');
mainDiv.appendChild(image);
image.height=100;
image.width=200;

t= setInterval(function(){
doImage(i++);
},1000);

}</script><div><div style="float:left; width:100px;"><div id="div1"></div><div id="div2"></div><div id="div3"></div></div><div style="float:left; width:200px; padding:50px;" id="MainDiv"></div><div style="float:left; width:100px;"><div id="div4"></div><div id="div5"></div><div id="div6"></div></div></div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: