我想在一定时间后消失警报框。我听说这在 Javascript 中是不可能的,那么还有其他方法可以实现吗?
			
			14393 次
		
3 回答
            3        
        
		
试试这个 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>
于 2013-09-06T06:06:34.163   回答
    
    
            0        
        
		
您可以使用自定义警报消息来执行此操作。通知框架的一个示例是 ToastR。您还可以创建自己的消息框架。但是,您不能关闭常规的 JavaScript 警报框。
于 2013-09-06T05:27:50.453   回答
    
    
            0        
        
		
工作演示——这是一个自定义的警报框和你需要的功能
function cancelDiv() {
        $("#div1").hide();
    }
    function ShowDiv() {
        $("#div1").css("backgroundColor", "white");
        $("#div1").show();
        setTimeout(function(){$("#div1").hide()}, 3000)
    }
    $(function () { 
        $("#div1").hide();
        $("#div1").draggable();            
    });
于 2013-09-06T05:37:48.430   回答