JavaScriptをalert()
自動的に閉じる方法はありますか?
アラートがあります
alert("Error found");
数秒後に閉じたい。それは可能ですか、それともjQueryダイアログに行きましょうか
JavaScriptをalert()
自動的に閉じる方法はありますか?
アラートがあります
alert("Error found");
数秒後に閉じたい。それは可能ですか、それともjQueryダイアログに行きましょうか
この機能は、アラートでは使用できません。ただし、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);
どうやってもアラートを閉じることはできません。
ただし、div を使用してアラート MSG を表示できます。
function Mymsg(msg,duration)
{
var alt = document.createElement("div");
alt.setAttribute("style","position:absolute;top:50%;left:50%;background-color:white;");
alt.innerHTML = msg;
setTimeout(function(){
alt.parentNode.removeChild(alt);
},duration);
document.body.appendChild(alt);
}
次のように使用できます。
Mymsg('close',2000)