我们可以使用 javascript 在警报中设置计时器吗?
我想制作一个带有计时器的警报, 警报将显示以下消息:
请等待处理数据3秒..
请等待处理数据2秒..
请等待处理数据1秒..
如果计时器完成,文本将更改为:
数据处理成功..
我尝试了这个:
function countdown() {
var seconds = 3;
function tick() {
var counter = document.getElementById("counter");
seconds--;
counter.innerHTML = "Please wait to process data " + String(seconds)+ " Second";
if( seconds > 0 ) {
setTimeout(tick, 1000);
} else {
alert("Succesfully process data");
}
}
tick();
}
countdown();
<div id="results"></div>
<button id="stop">Stop</button>
但是此代码将在 div 中显示计时器,而不是在警报中显示计时器。我尝试编辑以使其显示在警报中,但仍然无法弄清楚。
I want to make an alert that has a timer in it,
the alert will show this message:
Please wait to process data 3 second..
Please wait to process data 2 second..
Please wait to process data 1 second..
and if the timer is done, the text will change to:
Succesfully process data..
I tried this one:
function countdown() {
var seconds = 3;
function tick() {
var counter = document.getElementById("counter");
seconds--;
counter.innerHTML = "Please wait to process data " + String(seconds)+ " Second";
if( seconds > 0 ) {
setTimeout(tick, 1000);
} else {
alert("Succesfully process data");
}
}
tick();
}
countdown();
<div id="results"></div>
<button id="stop">Stop</button>
but this code will show the timer in div, not in alert. I tried to edit to make it show in alert but still can not figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论