Window对象

Window对象

获取:直接使用window,其中window可以省略

window.alert("abc");

属性:获取其他BOM对象
history: 对History对象的只读引用。
Navigator: 对Navigator对象的只读引用
Screen: 对Screen对象的只读引用
location: 用于窗口或框架的Location对象

方法:
alert(): 显示带有一段消息和一个确认按钮的警告框。
confirm(): 显示带有一段消息以及确认按钮和取消按钮的对话框
setInterval(): 按照指定的周期(以毫秒记)来调用函数或计算表达式
setTimeout(): 在指定的毫秒数后调用函数或计算表达式。

案列:实现灯泡的闪烁

<body>
<input type="button" onclick="on()" value="开灯">
<img id = "myImage" border="0" src="../imgs/off.gif" style="...">
<input type="button" onclick="off()" value="关灯">

<script>
    function on(){
        document.getElementById('myImage').src='../imgs/on.gif';
    }

    function off(){
        document.getElementById('myImage').src='../imgs/off.gif';
    }
    var x = 0;

    //根据一个变化的数组,产生固定个数的值:2 x % 2
    //定时器
    setInterval(function(){
        if (x % 2 == 0){
            on();
        }else{
            off();
        }
        x++;
    });
</script>
</body>