window对象(全局对象)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>window对象(全局对象)</title>
    <!-- 
        BOM是Browser Object Model的缩写,是浏览器对象模型
        核心是window对象,所有的全局变量和全局函数都被归在了window上
     -->
</head>
<body>
    <script>
        var a="我是全局变量";//声明全局变量
        alert(a);    
        window.b="我也是全局变量";//声明全局变量
        alert(b);
        window.sayName=function (){//声明全局函数
            document.write(this.b+"方法");//在window下找b
        }
        sayName();//调用函数
    </script>
</body>
</html>

posted on 2019-12-21 17:06  loongw  阅读(983)  评论(0编辑  收藏  举报

导航