<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
function init(){
time = setInterval("showAd()",3000);
}
function showAd(){
document.getElementById("img1").style.display="block";
//清除显示图片的定时操作
clearInterval(time);
time = setInterval("hiddenAd()",3000);
}
function hiddenAd(){
document.getElementById("img1").style.display="none";
//清除隐藏图片的定时操作
clearInterval(time);
}
</script>
</head>
<body onload="init()">
<p>111</p>
<img src="img/ad.jpg" style="display: none;" id="img1"/>
<p>222</p>
</body>
</html>