JavaScript学习笔记---03BOM

1.onload
window.onload = function () {
            document.write("the page is loaded");
            windo
        }
2.setInterval
<!DOCTYPE html>
<html lang="ch">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        window.onload = function () {

            var myinterval = setInterval(writeme, 1000);
            var mystop = document.getElementById("stop");
            mystop.onclick = function () {
            clearInterval(myinterval);
            }
        }
        function writeme() {
            var show = document.getElementById("div");
            show.innerHTML += Date("yy-m-d H:i:s") + "<br/>";
        }

    </script>
</head>

<body>
    <div id="div"></div>
    <input type="button" value="stop" id="stop" />
</body>

</html>

j结果:

3.history等

<script type="text/javascript">
    window.onload = function () {
        var mydiv;
        var refresh = document.getElementById("refresh");
        refresh.onclick = function () {
            mydiv = document.getElementById("div");
            mydiv.innerHTML += Date("yy-m-d H:i:s");
            history.go(0);
            //history.go(-3);
            //history.go(3);
        }
    }
</script>
4.location等

location.href

window.onload = function () {
           location.href="http://www.sina.com.cn";
        }

location.reload

<script type="text/javascript">
        window.onload = function () {
            var refresh = document.getElementById("refresh");
            var show = document.getElementById("show");
            show.innerHTML = Date("yy-m-d H:i:s")
            refresh.onclick = function () {
                location.reload(true);//师父重新载入
            }
        }
    </script>

setTimOut一定时间后执行函数

<script type="text/javascript">
        window.onload = function () {
            var refresh = document.getElementById("refresh");
            var show = document.getElementById("show");
            show.innerHTML = Date("yy-m-d H:i:s")
            refresh.onclick = function () {
                setTimeout(function () { location.href = "http://www.sohu.com" }, 5000);

            }
        }
    </script>
5.screen等
<script type="text/javascript">
        document.write(screen.availHeight + "px <br>");
        document.write(screen.availWidth + "px <br>");
        document.write(screen.width + "px <br>");
        document.write(screen.height + "px <br>");
    </script>

结果:
1040px
1920px
1920px
1080px

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值