BOM_Window_打开关闭方法与BOM_Window_定时器方法

BOM_Window_打开关闭方法

与打开关闭有关的方法
close() 关闭浏览器窗口
谁调用我,我光谁
open() 打开一个新的浏览器窗口
返回新的Window对象
 //打开新的窗口
        var openBtn = document.getElementById("openBtn");

        var newWindow;
            openBtn.onclick = function (){
                   //打开新的窗口
                newWindow= open("https://www.baidu.com");
            }
        //关闭新窗口
            var closeBtn = document.getElementById("closeBtn");
            closeBtn.onclick = function (){
                //关闭新窗口
                 newWindow.close("");
            }

BOM_Window_定时器方法

 

    

与定时器有关的方式
setTimeout() 在指定的毫秒数后调用函数或计算表达式。
参数:
1.js代码或者方法对象
2.毫秒值
返回值:唯一标识,用于取消定时器
clearTimeout() 取消由setTimeout()方法设置的timeout。

setInterval()按照指定的周期(以毫秒计)来调用函数或计算表达式。
clearInterval()取消由setInterval()设置的 timeout
  //一次性定时器
            //setTimeout("fun();",2000);

            //setTimeout(fun,2000);

           // var id =setTimeout(fun,2000);

           // clearTimeout(id);

             function fun(){
               alert('boom~~');
         }




            //循环定时器
            //setInterval(fun,2000);

            var id = setInterval(fun,2000);

             clearInterval(id);

 

posted @ 2022-11-19 16:57  zj勇敢飞,xx永相随  阅读(36)  评论(0编辑  收藏  举报