div代替window.alert,让这个div显示信息后,在指定之间时间内消失

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<div style="padding:2px;background:#06c none repeat scroll 0;position:absolute;z-index:3;color:white;top:1px;right:16px;display:none;" id="div_alert">&nbsp;添加成功…&nbsp;</div> 
<script type="text/javascript">
/*想写一个div代替window.alert,让这个div显示信息后,在指定之间时间内消失*/
         
function aler(elementId,times){
                 
this.elementId = elementId;
                 
this.times = times;
                 
this.show = function(){
                         window.setTimeout(
this.bbb,1000);
                 }
                 
this.bbb = function(){
                         document.getElementById(elementId).style.display
='';
                         window.setTimeout(
this.ccc,2000);//就这一句出问题了,请大家帮忙解决
                 }
                 ccc 
= function(){
                         document.getElementById(elementId).style.display
='none';

                 }
         }
         
var aaa = new aler('div_alert',2000);
         aaa.show();
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/zkxp/p/1100608.html