定时器

  • setInterval:每隔多少毫秒执行一次函数
  • setTimeout:多少毫秒之后执行一次函数
  • clearInterval:
  • clearTimeout:

广告弹出

  • 显示广告:img.style.display = "block"
  • 隐藏广告:img.style.display = "none"

广告弹出实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<script>
function init(){
setTimeout("showAD()",3000);
}
function showAD(){
//首先要获取要操作的img
var img = document.getElementById("img1");
//显示广告
img.style.display = "block";
//再开启定时器,关闭广告
setTimeout("hideAD()",3000);
}
function hideAD(){
//首先要获取要操作的img
var img = document.getElementById("img1");
//隐藏广告
img.style.display = "none";
}
</script>