其他分享
首页 > 其他分享> > 定时器 延时调用setTimeout

定时器 延时调用setTimeout

作者:互联网

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>定时器 延时调用setTimeout</title>
    <!-- 
        setTimeout("代码a",n);打开页面n毫秒后执行代码a
        clearTimeout(setTimeout());取消setTimeout();
     -->
</head>
<body>
    <script>
        var x;//全局变量x
        function a(){
            x=setTimeout("document.write('我在5秒后显示')",1000);//将定时代码赋值给x
        }
        function b(){
            clearTimeout(x);//清除x
        }
        a();//调用a
        b();//调用b
    </script>
</body>
</html>

标签:function,定时器,clearTimeout,调用,延时,setTimeout
来源: https://www.cnblogs.com/vinson-blog/p/12077403.html