自动关闭的对话框

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script language="javascript" type="text/javascript" >
  5.     function aaa() {
  6.         sAlert("asdfasdfa");
  7.         return false;
  8.     }
  9.     
  10.     var time = 5,timer=null;
  11. function dec() {
  12.     time--;
  13.     document.getElementById("time_pad").innerHTML = time;
  14.     if (time == 0){
  15.       document.getElementById("do_OK").fireEvent("onclick");
  16.       clearInterval(timer);//================清除计时器,因为你删除
  17.       timer=null;
  18.     }
  19. }
  20. function sAlert(txt) {
  21.     time = 5;
  22.     var shield = document.createElement("DIV");
  23.     shield.id = "shield";
  24.     shield.style.position = "absolute";
  25.     shield.style.left = "0px";
  26.     shield.style.top = "0px";
  27.     shield.style.width = "100%";
  28.     shield.style.height =  document.body.clientHeight; // + "px";
  29.     alert(document.body.clientHeight);
  30.     shield.style.background = "#333";
  31.     shield.style.textAlign = "center";
  32.     shield.style.zIndex = "10000";
  33.     shield.style.filter = "alpha(opacity=0)";
  34.     shield.style.opacity = 0;
  35.     var alertFram = document.createElement("DIV");
  36.     alertFram.id = "alertFram";
  37.     alertFram.style.position = "absolute";
  38.     alertFram.style.left = "50%";
  39.     alertFram.style.top = "50%";
  40.     alertFram.style.marginLeft = "-225px";
  41.     alertFram.style.marginTop = -75 + document.documentElement.scrollTop + "px";
  42.     alertFram.style.width = "450px";
  43.     alertFram.style.height = "auto";
  44.     alertFram.style.background = "#ccc";
  45.     alertFram.style.textAlign = "center";
  46.     alertFram.style.lineHeight = "150px";
  47.     alertFram.style.zIndex = "10001";
  48.     strHtml = " <ul style=/"list-style:none;margin:0px;padding:0px;width:100%/"> /n";
  49.     strHtml += "  <li style=/"background:#DD828D;text-align:left;padding-left:20px;font-size:18px;font-weight:bold;height:25px;line-height:25px;border:1px solid #F9CADE;/">[提示]:     <span id='time_pad' style=/"color:red;font-family:Verdana;font-weight:bold;/">" + time + "</span>秒钟后关闭" + " </li>  /n";
  50.     strHtml += "  <li style=/"background:#fff;text-align:center;font-size:14px;height:120px;line-height:120px;border-left:1px solid #F9CADE;border-right:1px solid #F9CADE;/"> " + txt + " </li> /n";
  51.     strHtml += "  <li style=/"background:#FDEEF4;text-align:center;font-weight:bold;height:25px;line-height:25px; border:1px solid #F9CADE;/"> <input type=/"button/" value=/" 确 定 /" id=/"do_OK/" onclick=/"doOk()/" style=/"width:60px/" /> </li> /n";
  52.     strHtml += " </ul> /n";
  53.     alertFram.innerHTML = strHtml;
  54.     document.body.appendChild(alertFram);
  55.     document.body.appendChild(shield);
  56.     this.setOpacity = function(obj, opacity) {
  57.         if (opacity >= 1) opacityopacity = opacity / 100;
  58.         try { obj.style.opacity = opacity; } catch (e) { }
  59.         try {
  60.             if (obj.filters.length > 0 && obj.filters("alpha")) {
  61.                 obj.filters("alpha").opacity = opacity * 150;
  62.             } else {
  63.                 obj.style.filter = "alpha(opacity=/"" + (opacity * 150) + "/")";
  64.             }
  65.         } catch (e) { }
  66.     }
  67.     var c = 0;
  68.     this.doAlpha = function() {
  69.         if (++c > 20) { clearInterval(ad); return 0; }
  70.         setOpacity(shield, c);
  71.     }
  72.     var ad = setInterval("doAlpha()", 1);
  73.     this.doOk = function() {
  74.         if (timer) { clearInterval(timer); timer = null; } //================清除计时器
  75.         document.body.removeChild(alertFram);
  76.         document.body.removeChild(shield);
  77.         document.body.onselectstart = function() { return true; }
  78.         document.body.oncontextmenu = function() { return true; }
  79.     }
  80.     document.getElementById("do_OK").focus();
  81.     document.body.onselectstart = function() { return false; }
  82.     document.body.oncontextmenu = function() { return false; }
  83.     
  84.     timer=window.setInterval("dec()", 1000);//=================放最后,防止未生成控件
  85. }
  86. </script>
  87.     <title></title>
  88. </head>
  89. <body>
  90.     <p>
  91.         <input id="Button1" type="button" value="button" onclick="aaa()" /><input type="submit" ID="Button2" valule="Button"  OnClick=" return aaa()"/></p>
  92.     <p>
  93.          </p>
  94.     <p>
  95.          </p>
  96. </body>
  97. </html>

 

原文地址:http://topic.csdn.net/u/20081018/20/c652cb3f-cac5-4f17-961f-510b11f6e3f0.html

 

改自原来收藏的一个代码,多谢 showdo帮忙修改

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值