简体   繁体   English

5秒后打开弹出窗口我在做什么错?

[英]Open Popup after 5 seconds what am I doing wrong?

I placed a popup on page load, but I would prefer to appear after 5 seconds. 我在页面加载中放置了一个弹出窗口,但我希望5秒后出现。 I inserted tie out code, but it is not working what am I doing wrong? 我插入了绑定代码,但无法正常工作,我在做什么错?

<script type="text/javascript">

        var link;
        var element;
                    t=setTimeout(openpopupFunction,5000);
        function openPopUp(url)
        {
            link = url;
            element = document.getElementById("background");
            element.style.display = "block";
            element = document.getElementById("popup");
            element.style.display = "block";

        }
</script>

You are using a different function name when you try to call it. 当您尝试调用它时,您正在使用其他函数名称。 Use: 采用:

var t = setTimeout(openPopUp, 5000);

You only need the variable t here if you need to stop the timeout. 如果您需要停止超时,则只需在此处使用变量t

Side note: You would normally declare the variables link and element inside the function so that they are local, not global variables. 旁注:通常,您应在函数内部声明变量linkelement ,以便它们是局部变量,而不是全局变量。 Try to keep as little as possible in the global scope, to minimise the risk of conflicts between scripts and with other things that are already in the global scope. 尽力将其保留在全局范围内,以使脚本之间以及与全局范围内已存在的其他事物发生冲突的风险最小化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM