简体   繁体   English

警报框中的确定按钮

[英]OK button in Alert Box

I need to put an alert box with the message “Welcome.”我需要放置一个带有“欢迎”消息的警告框。 after every 5 seconds and will only exit after 5 times of clicking the OK button?每 5 秒后,并且仅在单击 OK 按钮 5 次后才会退出? Is that possible?那可能吗?

Sumit's answer does work Sumit的回答确实有效

I have turned it into a snippet to run here on Stack Overflow itself, and added numbers to the "Welcome" message, so you can follow its progress through the 5 clicks.我已经把它变成了一个片段,在 Stack Overflow 上运行,并在“欢迎”消息中添加了数字,所以你可以通过 5 次点击来跟踪它的进度。

 const callWelcome = () => { alert('Welcome 1'); alert('Welcome 2'); alert('Welcome 3'); alert('Welcome 4'); alert('Welcome 5'); } setTimeout(callWelcome, 5000);

I am confident this will work for you, because it is here on this site.我相信这对你有用,因为它在这个网站上。 If it doesn't, please indicate what "Welcome" message you are seeing, ie what number?如果没有,请说明您看到的是什么“欢迎”消息,即什么号码?

More closely match what you asked for更符合您的要求

From my reading of your questions, you want a 5 second delay BEFORE the first alert, but then a NEW 5 second delay after closing the first alert, before opening the next alert, and so on.根据我对您的问题的阅读,您希望在第一个警报之前延迟 5 秒,然后在关闭第一个警报后、在打开下一个警报之前再延迟 5 秒,依此类推。 If so, this will do the trick.如果是这样,这将解决问题。

 setTimeout(() => { alert('Welcome 1'); setTimeout(() => { alert('Welcome 2'); setTimeout(() => { alert('Welcome 3'); setTimeout(() => { alert('Welcome 4'); setTimeout(() => { alert('Welcome 5'); }, 5000); }, 5000); }, 5000); }, 5000); }, 5000);

So from your comment now, I realise you mean it should keep going round that loop?所以从你现在的评论中,我意识到你的意思是它应该继续循环下去?

It was not clear in your question, I am afraid.恐怕你的问题不清楚。 I now think you meant to say, "after 5 seconds, there is a welcome message, which you have to click 5 times to make it go away, and after that, after a 5 second delay, it reappears, and so on."我现在认为您的意思是说,“5 秒后,有一条欢迎消息,您必须单击 5 次才能使其 go 消失,然后在 5 秒延迟后重新出现,依此类推。”

 function fivefoldMessage() { alert('Welcome 1'); alert('Welcome 2'); alert('Welcome 3'); alert('Welcome 4'); alert('Welcome 5'); setTimeout(fivefoldMessage, 5000) } setTimeout(fivefoldMessage, 5000)

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

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