简体   繁体   English

如何使我的弹出窗口永久关闭?

[英]How do I get my popup form to close permanently?

I'm making a pop-up 'subscribe to the mailing list' form for my website. 我正在为我的网站制作一个弹出式的“订阅邮件列表”表格。 I have a button that is supposed to close the form with this function: 我有一个应该使用此功能关闭表单的按钮:

function closeForm() {
  document.getElementById("mailsub").style.display = "none";
}

but, seemingly due to also having this function to open the form: 但是,似乎是由于还具有打开表单的功能:

setInterval(function openForm() {
  document.getElementById("mailsub").style.display = "block";
}, 700);

when you close the form, it just opens again after 0.7 seconds. 当您关闭表单时,它仅在0.7秒后再次打开。

Does anyone know how to make it so the form closes indefinitely while preserving the function to open the form? 有谁知道如何做到这一点,以便在保留打开表单功能的同时无限期关闭表单?

Thanks in advance. 提前致谢。

setInterval - This will run every 700 milliseconds . setInterval-这将每700毫秒运行一次。 so use setTimeout. 因此请使用setTimeout。 It will run once after 700milliseconds 它将在700毫秒后运行一次

setTimeout(function openForm() {
  document.getElementById("mailsub").style.display = "block";
}, 700);

setInterval will cause the functinon that open the popup to be called every 0.7 seconds. setInterval将导致每0.7秒调用一次打开弹出窗口的功能。 Change it to setTimeout, and it will only fire once: 将其更改为setTimeout,它将仅触发一次:

setTimeout(function openForm() {
  document.getElementById("mailsub").style.display = "block";
}, 700);

You have to use toggle to set display none or block. 您必须使用切换按钮来设置不显示或不显示。 And with that you can use it if true use block else none. 这样,如果使用true,则可以使用它,否则不使用。 I can quickly write code for you as well. 我也可以为您快速编写代码。

shouldOpen ? 'block' : 'none'

shouldOpen hold value true or false and that will be set on the basis of your business rule. shouldOpen保留值truefalse ,并将根据您的业务规则进行设置。

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

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