我想仅显示警报框3秒钟(表示它自动显示和隐藏).我在谷歌搜索很多但没有得到答案.任何建议真的很感激.
我已经完成了新窗口,但仍然找到带警报框的解决方案.Chk我的代码:
function fn() {
var w = window.open('', '', 'width=300,height=2px')
w.document.write('Product has been added to your Order List !')
w.focus()
setTimeout(function () { w.close(); }, 2000);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
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);
}
Run Code Online (Sandbox Code Playgroud)
像这样使用它:
tempAlert("close",5000);
Run Code Online (Sandbox Code Playgroud)