Autoclose alert

后端 未结 4 2176
醉酒成梦
醉酒成梦 2020-12-04 02:05

Is there any way to close a javascript alert() automatically?

I have an alert

alert(\"Error found\");

I want to close

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 02:30

    You can't close alert any how .

    But you can use div To show your alert 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);
    }
    

    You can use as :

    Mymsg('close',2000)
    

提交回复
热议问题