簡體   English   中英

以時間為基礎消除警報框

[英]Disappear the alert box with time based

我想在一段時間后消失警報框。 我聽說這在Javascript中是不可能的,那么有沒有其他方法可以實現這一點?

試試這個jsbin代碼 - 一個自定義警告框

http://jsbin.com/ibUrIxu/1/edit

或者在.html文件中試試這個

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script>
function customAlert(msg,duration)
{
 var styler = document.createElement("div");
  styler.setAttribute("style","border: solid 5px Red;width:auto;height:auto;top:50%;left:40%;background-color:#444;color:Silver");
 styler.innerHTML = "<h1>"+msg+"</h1>";
 setTimeout(function()
 {
   styler.parentNode.removeChild(styler);
 },duration);
 document.body.appendChild(styler);
}
  function caller()
  {
    customAlert("This custom alert box will be closed in 2 seconds","2000");
  }
  </script>
  </head>
<body onload="caller()">

</body>
</html>

您可以使用自定義警報消息執行此操作。 通知框架的一個示例是ToastR。 您還可以創建自己的消息框架。 但是,您無法關閉常規JavaScript警報框。

工作演示 - 這是一個自定義警報框,可以滿足您的需求

function cancelDiv() {
        $("#div1").hide();
    }

    function ShowDiv() {
        $("#div1").css("backgroundColor", "white");
        $("#div1").show();
        setTimeout(function(){$("#div1").hide()}, 3000)
    }

    $(function () { 
        $("#div1").hide();
        $("#div1").draggable();            
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM