zoukankan      html  css  js  c++  java
  • 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=" 400px">
                <input type="submit" value="开始" onclick="begin_interval()">
                <input type="submit" value="结束" onclick="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="前进" onclick="func1()">
        <script>
            function func1() {
                history.forward();
                history.go(1)和history.forward()效果是一样的
            }
        </script>
    
    
    
        在第二个html文档中这样写
        <input type="button" value="后退" onclick="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="重载" onclick="func1()">
                <script>
                    function func1() {
                        location.reload()
                }
                </script>
    
            href方法,实现和超链接a标签的href一样的作用,就会跳转到href指向的地址
            <input type="button" value="超链接" onclick="func2()">
    
            function func2() {
                location.href="www.baidu.com"
            }
    

      

  • 相关阅读:
    MySQL SQL语句总结
    JavaFx通用查询、跳转创建、修改页面、关闭舞台工具类
    反射工具类
    SpringBoot将数据写入word模板,生成word文档
    vscode设置中文的方法
    Flex 布局
    处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler” •使用了托管的处理程序,但是未安装或未完整安装 ASP.NET。
    第一周助教总结
    JS时间转换
    ES 安装常见错误
  • 原文地址:https://www.cnblogs.com/bainianminguo/p/8661000.html
Copyright © 2011-2022 走看看