JavaScript的windows对象常用方法

电子表事件:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function showtime() {
            //创建事件对象,获得当前时间,并在页面上显示
            var d = new Date();
            var year = d.getFullYear();
            var month = d.getMonth();
            var riqi = d.getDate();

            var hour = d.getHours();
            var minute = d.getMinutes();
            var second = d.getSeconds();
            var timeinfo = year + "-" + month + "-" + riqi + " " + hour + ":" + minute + ":" + second;
            //innerHTML可以设置、获取一个标签内部应有的信息
            document.getElementsByTagName('h2')[0].innerHTML = timeinfo;
        }
        //showtime函数需要每间隔一秒就执行一次
        window.onload = function () {
            //setInterval(全局变量处理)
            mytime = setInterval("showtime()", 1000);
        }
        function cancel() {
            clearInterval(mytime);
        }
    </script>
    <style type="text/css">
        div {width: 300px; height: 200px; background: lightblue;}
    </style>
</head>
<body>
    <h2></h2>
    <input type="button" value="取消" οnclick="cancel()" >
</body>
</html>

效果图:


open方法:

open() 开启新浏览视窗

fullscreen=yes or no 使用全屏幕

height=number of pixels 设定视窗高度

width= number of pixels 设定视窗宽度

left =  number of pixels 设定视窗左边界

top =  number of pixels 设定视窗上边界

resizable=yes or no 是否允许改变视窗大小

menubar=yes or no 是否使用功能表

toolbar=yes or no 是否使用工具列

location=yes or no 是否使用位址栏

directories=yes or no 是否使用目录钮

status=yes or no 是否使用状态栏

scrollbars=yes or no 是否使用滚动条

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function newpage() {
            //window.open(被显示页面的名字, 页面打开方式, 页面参数);
            //页面打开方式:_self 在本窗口打开页面   _blank 在新窗口打开页面  _top frame的name属性值
            window.open('26.html', '_blank', "width=573, height=275, directories=yes");
        }
    </script>
    <style type="text/css">
        div {width: 300px; height: 200px; background: lightblue;}
    </style>
</head>
<body>
    <h2>创建子集页面</h2>
    <input type="button" value="创建" οnclick="newpage()" >
</body>
</html>

效果图:



open方法弹出页面将信息返回到父页面

子页面:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        window.onload = function () {
            var dv = document.getElementsByTagName('div')[0];
            //点击div,把其内部的信息追加给父级页面
            dv.onclick = function () {
                //opener表示父级页面
                opener.document.getElementsByTagName('h2')[0].innerHTML = this.innerHTML;
            }
        }
    </script>
    <style type="text/css">
        div {width: 300px; height: 200px; background: lightblue;}
    </style>
</head>
<body>
    <h2>son page</h2>
    <div>hello</div>
</body>
</html>


父页面:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function newpage() {
            //window.open(被显示页面的名字, 页面打开方式, 页面参数);
            //页面打开方式:_self 在本窗口打开页面   _blank 在新窗口打开页面  _top frame的name属性值
            window.open('26.html', '_blank', "width=573, height=275, directories=yes");
        }
    </script>
    <style type="text/css">
        div {width: 300px; height: 200px; background: lightblue;}
    </style>
</head>
<body>
    <h2>创建子集页面</h2>
    <input type="button" value="创建" οnclick="newpage()" >
</body>
</html>

效果图:




点击子页面的div,父页面的创建子页面变为hello


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值