请问该如何用window.onload=function()写上一个定时器?

我已经做好了HTML页面如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#tab { overflow:hidden; width:400px; height:250px; position:relative; float:left;}
</style>
</head>

<body>
<div id="tab">
<img src="img/01.jpg" width="400" height="250"/>
<img src="img/02.jpg" width="400" height="250"/>
<img src="img/03.jpg" width="400" height="250"/>
</div>

<script>

</script>
</body>
</html>

如何用window.onload=function(){写上一个定时器},具体用JS怎么写...谢谢

LEATH
浏览 235回答 1
1回答

叮当猫咪

<!DOCTYPE&nbsp;html><html><head><meta&nbsp;http-equiv="Content-Type"&nbsp;content="text/html;&nbsp;charset=utf-8"&nbsp;/><title>无标题文档</title><style&nbsp;type="text/css">#tab&nbsp;{&nbsp;overflow:hidden;&nbsp;width:400px;&nbsp;height:250px;&nbsp;position:relative;&nbsp;float:left;}#tab>img:not(:first-child){&nbsp;display:none;&nbsp;}&nbsp;</style><script>&nbsp;&nbsp;&nbsp;&nbsp;window.onload&nbsp;=&nbsp;function(){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;images&nbsp;=&nbsp;document.getElementsByTagName('img');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;pos&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;len&nbsp;=&nbsp;images.length;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setInterval(function(){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;images[pos].style.display&nbsp;=&nbsp;'none';&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos&nbsp;=&nbsp;++pos&nbsp;==&nbsp;len&nbsp;?&nbsp;0&nbsp;:&nbsp;pos;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;images[pos].style.display&nbsp;=&nbsp;'inline';&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},1000);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};</script>&nbsp;</head>&nbsp;<body><div&nbsp;id="tab">&nbsp;&nbsp;&nbsp;&nbsp;<img&nbsp;src="img/01.jpg"&nbsp;width="400"&nbsp;height="250"/>&nbsp;&nbsp;&nbsp;&nbsp;<img&nbsp;src="img/02.jpg"&nbsp;width="400"&nbsp;height="250"/>&nbsp;&nbsp;&nbsp;&nbsp;<img&nbsp;src="img/03.jpg"&nbsp;width="400"&nbsp;height="250"/></div></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP