首页 > 编程语言 > 详细

JavaScript:Window对象概述

时间:2020-04-25 14:37:24      阅读:44      评论:0      收藏:0      [点我收藏+]

Window对象常用属性和方法

(1)简单对话框:alert()、confirm()和prompt();

<html>
    <head>
        <title>简单对话框</title>
    </head>
    <body>
            <script>
                var yourname = prompt("您的名字是:");
                //console.log(yourname);
                if(confirm("您确定吗?")==true)
                {
                    alert(yourname+"先生,你好");
                } 
            </script>
    </body>
</html>

运行结果:

技术分享图片

 

 

 

(2)状态栏:status属性和defaultStatus属性;(一般不支持用,这里就不说了)

(3)定时设定和时间间隔:setTimeout()、clearTimeout()、setlterval()、clertlnterval();

<html>
    <head>
        <title>定时设定和时间间隔</title>
    </head>
    <body>
        <script type="text/javascript">
            function display()
            {
                var content = document.getElementById("text");
                content.value= new Date().toLocaleString();
            }
            window.onload=function()
            {
                var timer;
                document.getElementById("start").onclick=function()
                {
                    timer = setInterval(‘display()‘,1000);
                }
                document.getElementById("stop").onclick=function()
                {
                    clearInterval(timer);
                }
            }
            
        </script>
        <input type="text" value="" id="text" size=30/>
        <input type="button" value="开始" id="start" />
        <input type="button" value="结束" id="stop" />
     </body>
</html>

运行结果如下:

技术分享图片

 

 

 (4)navigator:用于获取浏览器和操作系统的信息;

(5)Screen对象:有关用户显示器的大小和可用的颜色数量信息;

<html>
    <head>
        <title>navigator对象和Screen对象</title>
    </head>
    <body>
        <input type="button" id="demo1" value="显示浏览器信息"/>
        <input type="button" id="demo2" value="显示屏幕信息"/>
        <script type="text/javascript">
            document.getElementById("demo1").onclick=
            function()
            {
            alert
            (
                "浏览器信息:\n"+
                "名称:"+navigator.appName+"\n"+
                "平台和版本:"+navigator.appVersion+"\n"+
                "操作系统:"+navigator.platform+"\n"+
                "userAgent"+navigator.userAgent
            );
            }
            document.getElementById("demo2").onclick=
            function()
            {
            alert
            (
                "屏幕信息:\n"+
                "分辨率:"+screen.width+"*"+screen.height+"\n"+
                "可用区域"+screen.availWidth+"*"+screen.availHeight
            );
            }
        </script>
    </body>
</html>

运行结果如下:

技术分享图片

 

 

技术分享图片

 

JavaScript:Window对象概述

原文:https://www.cnblogs.com/daitu/p/12772685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!