File size: 1,504 Bytes
08aee07 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Window对象</title>
</head>
<body>
<script>
/*
4、与定时器有关的方式
setTimeout() 在指定的毫秒数后调用函数或计算表达式。
* 参数:
1. js代码或者方法对象
2. 毫秒值
* 返回值:唯一标识,用于取消定时器
clearTimeout() 取消由 setTimeout() 方法设置的 timeout。
setInterval() 按照指定的周期(以毫秒计)来调用函数或计算表达式。
clearInterval() 取消由 setInterval() 设置的 timeout。
*/
//一次性的定时器
var id = setTimeout(fun, 2000);
function fun(){
alert('boom~');
}
clearTimeout(id);//取消执行
//循环定时器
var id2 = setInterval(fun, 5000);
clearInterval(id2);
/*
5、属性:
1. 获取其他BOM对象:
history
location
Navigator
Screen:
2. 获取DOM对象
document
*/
var h1 = window.history;
alert(h1);
window.document.write('BOM中的Window对象可以获取DOM中的document对象');
</script>
</body>
</html> |