Bom对象介绍

1、windows对象

1、windows对象
        1_1、alert:显示一段消息和确认按钮的弹出的警告框
            我们平时用的alert的全称就是
            window.alert("hahah");


        1_2、confirm:显示一段消息和确认按钮和取消的对话框
            confirm有个返回值,如果是确定,则返回true,如果是取消,则是false

            var ret = window.confirm("hello confirm");
            console.log(ret)


        1_3、prompt:显示可提示用户输入的对话框

            prompt可以有一个返回值,接受用户输入的内容
            var ret = window.prompt("hello prompt")
            console.log(ret)

        1_4、open:打开一个新的浏览器的窗口或者查看一个已命名的窗口

        1_5、close:关闭浏览器的窗口


        1_6、setInterval:控制指定周期内循环做某件事情


        1_7、clearInterval:取消setInterval设定的计算表达式

        interval的例子,点击开始按钮,开始显示时间,且1000毫秒后再次执行begin函数
            <input type="text" id="clock" style="width: 400px">
            <input type="submit" value="开始" οnclick="begin_interval()">
            <input type="submit" value="结束" οnclick="end_interval()">

            <script>
        //        window.alert("hahah");


        //        var ret = window.confirm("hello confirm");
        //        console.log(ret)

        //        var ret = window.prompt("hello prompt")
        //        console.log(ret)

            var ID
            function begin() {
               var d = new Date()
                var ret = document.getElementById("clock");
               ret.value = d;

            }
            function begin_interval() {
                ID = setInterval(begin,1000);
                //    每隔1000毫秒执行begin这个函数,这个id的意思每隔定时器都有一个唯一的标志,就是id,用来区分不同的定时器
            }



            function end_interval() {
        //        prompt("hello prompt")
                clearInterval(ID)
            }



        1_8、setTimeout:设置指定秒数后调用某个函数或者表达式
                function timeout() {
            alert("123")
             }

        var id = setTimeout(timeout,1000)



        1_9、clearTimeout:取消setTimeout的设置

            clearTimeout(id)
            取消id为id这个事件
        1_10、

  

2、history对象

1、history对象,内部有三种方法,一个是forward,一个back,一个是go


用法实例forward和back的用法,go中有个参数,为1,则和forward的用法一样,go中的参数为-1,则和back的用法是一样的,参数为0,则不跳转的意思
   在第一个html文档中这样写
    <a href="html2.html">html2</a>
    <input type="button" value="前进" οnclick="func1()">
    <script>
        function func1() {
            history.forward();
            history.go(1)和history.forward()效果是一样的
        }
    </script>



    在第二个html文档中这样写
    <input type="button" value="后退" οnclick="func2()">

    <script>
        function func2() {
            history.back()
            history.go(-1)和history.back()效果是一样的

        }
    </script>


    首先打开第一个html文档,然后点击a连接,连接到html2,然后在打开的第二个html文档中点击后退按钮,执行func2函数,就是会history.back的功能,跳转到
    第一个html文档中



    alert(history.length)返回这个页面保存了多少个页面

  

3、location对象

 reload方法:实现刷新本页面的功能
            <input type="button" value="重载" οnclick="func1()">
            <script>
                function func1() {
                    location.reload()
            }
            </script>

        href方法,实现和超链接a标签的href一样的作用,就会跳转到href指向的地址
        <input type="button" value="超链接" οnclick="func2()">

        function func2() {
            location.href="www.baidu.com"
        }

  

转载于:https://www.cnblogs.com/bainianminguo/p/8661000.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值