我已經(jīng)做好了HTML頁(yè)面如下:<!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>無(wú)標(biāo)題文檔</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(){寫(xiě)上一個(gè)定時(shí)器},具體用JS怎么寫(xiě)...謝謝
1 回答

叮當(dāng)貓咪
TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
<!DOCTYPE html> < html > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> < title >無(wú)標(biāo)題文檔</ title > < style type = "text/css" > #tab { overflow:hidden; width:400px; height:250px; position:relative; float:left;} #tab>img:not(:first-child){ display:none; } </ style > < script > window.onload = function(){ var images = document.getElementsByTagName('img'); var pos = 0; var len = images.length; setInterval(function(){ images[pos].style.display = 'none'; pos = ++pos == len ? 0 : pos; images[pos].style.display = 'inline'; },1000); }; </ script > </ 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 > </ body > </ html > |
添加回答
舉報(bào)
0/150
提交
取消