自动关闭警报 [英] Autoclose alert
本文介绍了自动关闭警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法自动关闭javascript alert()
?
Is there any way to close a javascript alert()
automatically?
我有警报
alert("Error found");
我想在几秒后关闭它。这是可能的还是我应该去jQuery对话
I want to close it after a few second. Is that possible or shall I go for jQuery dialogue
推荐答案
jsFiddle Demo
警报无法实现此功能。但是,您可以使用div
This functionality is not possible with an alert. However, you could use a div
function tempAlert(msg,duration)
{
var el = document.createElement("div");
el.setAttribute("style","position:absolute;top:40%;left:20%;background-color:white;");
el.innerHTML = msg;
setTimeout(function(){
el.parentNode.removeChild(el);
},duration);
document.body.appendChild(el);
}
使用这样:
tempAlert("close",1000);
这篇关于自动关闭警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文