弹出提示框 自动消失

 我们在进行增、删、改、查的时候,很多时候都需要一个提示信息以表明所做操作的成功等状况。有些人喜欢用alert()来提示,这不太人性化,因为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>
<script language="javascript" type="text/javascript">
var speed=1000;
var wait=2;
var intTimeStep=20;
var isIe=(window.ActiveXObject)?true:false;
var intAlphaStep=(isIe)?5:0.05;
var curSObj=null;
var curOpacity=null;
function startObjVisible(objId)
{
   curSObj=document.getElementById(objId);
    if(wait==0)
    {
   setObjClose();
 }
    else
    {
      curSObj.style.display='';
      setObjOpen();
   wait--;  
      setTimeout("startObjVisible('objDiv')",speed);
    }
}

function setObjOpen()
{
  if(isIe)
  {
  curSObj.filters.alpha.opacity+=intAlphaStep;
     if (curSObj.filters.alpha.opacity<100)
   {
       setTimeout('setObjOpen()',intTimeStep);
   }
  }
  else
  { 
     curOpacity+=intAlphaStep;
     curSObj.style.opacity =curOpacity;
     if (curOpacity<1) setTimeout('setObjOpen()',intTimeStep);
  }
}

function setObjClose()
{
  if(isIe)
  {
      curSObj.filters.alpha.opacity-=intAlphaStep;
      if (curSObj.filters.alpha.opacity>0)
        {
         setTimeout('setObjClose()',intTimeStep);
        }
      else
     {
  curSObj.style.display="none";
  }
  }
  else
  {
       curOpacity-=intAlphaStep;
       if (curOpacity>0)
      {
            curSObj.style.opacity =curOpacity;
            setTimeout('setObjClose()',intTimeStep);
      }
       else
      {
        curSObj.style.display='none';
         }
   }
}
</script>
</head>
<body>
 <input type="button" onClick="startObjVisible('objDiv')" value="添加数据" />
<div id="objDiv" style="display:none; z-index:999; left:100px; filter:alpha(opacity=0);position:absolute; background-color:#FFCC66; height:100px; width:200px;">添加成功 </div>
</body>
</html>

 

posted @ 2009-05-06 23:23  郑希强  阅读(1511)  评论(1编辑  收藏  举报