GCT1015
2023-01-03 18:14:29
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無(wú)標(biāo)題文檔</title><script type="text/javascript">var currentImgNumber=1;var numberOfImages=3;function window_onload(){setTimeout("switchImage()",3000);}function switchImage(){currentImgNumber++;document.imgAdvert.src='AdvertImage'+currentImgNumber+'.jpg';if(currentImgNumber<numberOfImages){setTimeout("switchImage()",3000);}}</script></head><body onload="window_onload()"><img src="AdvertImage1.jpg" name="imgAdvert" /></body>小弟新手一個(gè),請(qǐng)哪位大佬指點(diǎn)指點(diǎn)!
2 回答

慕運(yùn)維8079593
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
setTimeout()只是定時(shí)執(zhí)行一次,用setInterval();定時(shí)不斷執(zhí)行

元芳怎么了
TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊
var
currentImgNumber=0;
// 0~2
var
numberOfImages=3;
function
window_onload()
{
setTimeout(
"switchImage()"
,3000);
}
function
switchImage()
{
document.imgAdvert.src=
'AdvertImage'
+(currentImgNumber+1)+
'.jpg'
;
currentImgNumber++;
currentImgNumber %= numberOfImages;
setTimeout(
"switchImage()"
,3000);
}
添加回答
舉報(bào)
0/150
提交
取消