繁体   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