JS中window对象的使用

来源:互联网 发布:淘宝会员注册网站 编辑:程序博客网 时间:2024/06/05 19:44
<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>window对象的使用</title>        <!--            作者:李瑞琦            时间:2017-08-23            描述:        -->        <script type="text/javascript">            function testAlert(){                window.alert("我是警告框");            }            function testConfirm(){                var flag = window.confirm("你确定要退出吗");            }            function testPrompt(){                var flag = window.prompt("请输入昵称");            }            //定时执行            //定义全局变量记录线程id            var id;            var num;            //定时执行            function testTimeOut(){                id = window.setTimeout(function(){                    alert("定时执行");                },2000);            }            //结束定时执行的线程            function clearTimeOut(){                window.clearTimeout(id);            }            //间隔执行            function testInterval(){                num = window.setInterval(function(){                    alert("间隔执行")                },3000);            }            //结束间隔执行的线程            function clearInterval(){                window.clearInterval(num);            }        </script>    </head>    <body>        <h3>window对象的使用</h3>        <hr />        <input type="button" id="" name="" value="testAlert" onclick="testAlert()" />        <input type="button" id="" name="" value="testConfirm" onclick="testConfirm()" />        <input type="button" id="" name="" value="testPrompt" onclick="testPrompt()" />        <hr />        <input type="button" id="" name="" value="testTimeout" onclick="testTimeOut()" />        <input type="button" id="" name="" value="testClearTimeout" onclick="clearTimeOut()" />        <input type="button" id="" name="" value="testInterval" onclick="testInterval()" />        <input type="button" id="" name="" value="clearInterval" onclick="clearInterval()" />    </body></html>