zoukankan      html  css  js  c++  java
  • 【Wonder整理】防止重复提交并弹出半透明对话框

    一、JavaScript代码:

    代码
    1 <script language="javascript">
    2 var isIe=(document.all)?true:false;
    3 //设置select的可见状态
    4   function setSelectState(state)
    5 {
    6 var objl=document.getElementsByTagName('select');
    7 for(var i=0;i<objl.length;i++){
    8 objl[i].style.visibility=state;
    9 }
    10 }
    11 function mousePosition(ev)
    12 {
    13 if(ev.pageX || ev.pageY){
    14 return {x:ev.pageX, y:ev.pageY};
    15 }
    16 return{
    17 x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
    18 };
    19 }
    20 //弹出方法
    21   function showMessageBox(ev,wTitle,content,wWidth,isShowClose)
    22 {
    23 if( confirm('Confirm to Continue (确认此操作)?') )
    24 {
    25 var pos = mousePosition(ev);
    26 closeWindow();
    27 var bWidth=parseInt(document.documentElement.scrollWidth);
    28 var bHeight=parseInt(document.documentElement.scrollHeight);
    29 if(isIe){
    30 setSelectState('hidden');
    31 }
    32 var back=document.createElement("div");
    33 back.id="back";
    34 var styleStr="top:0px;left:0px;position:absolute;background:#666;"+bWidth+"px;height:"+bHeight+"px;";
    35 styleStr+=(isIe)?"filter:alpha(opacity=30);":"opacity:30;";
    36 back.style.cssText=styleStr;
    37 document.body.appendChild(back);
    38 showBackground(back,50);
    39 var mesW=document.createElement("div");
    40 mesW.id="mesWindow";
    41
    42 var html = "<div style='border-bottom: #eee 1px solid;margin-left: 4px;padding: 3px;font-weight: bold;text-align: left;font-size: 12px;'>";
    43 html += "<table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='1px;'>";
    44 if( isShowClose == 1 )
    45 {
    46 html += "<input type='button' onclick='closeWindow();' title='Close(关闭窗口)' style='height: 15px; 28px;border: none;cursor: pointer;text-decoration: underline;background: #fff;' value='关闭' />";
    47 }
    48 html += "</td></tr></table></div><div style='margin: 4px;font-size: 12px;padding:20px 0 20px 0;text-align:center' id='mesWindowContent'>"+content+"</div>";
    49 mesW.innerHTML= html ;
    50 var v_top=(document.body.clientHeight-mesW.clientHeight)/3;
    51 v_top+=document.documentElement.scrollTop;
    52
    53 styleStr="border:#666 1px solid;background:#fff;top:"+v_top+"px;left:"+(document.body.clientWidth/2-mesW.clientWidth/2)+"px;position:absolute;600px;margin-left:-300px;left:50%;z-index:9999;";
    54 mesW.style.cssText = styleStr;
    55
    56 document.body.appendChild(mesW);
    57 return true;
    58 }
    59 else
    60 return false;
    61 }
    62 //让背景渐渐变暗
    63 function showBackground(obj,endInt)
    64 {
    65 if(isIe){
    66 obj.filters.alpha.opacity+=5;
    67 if(obj.filters.alpha.opacity<endInt){
    68 setTimeout(function(){showBackground(obj,endInt)},1);
    69 }
    70 }else{
    71 var al=parseFloat(obj.style.opacity);al+=0.05;
    72 obj.style.opacity=al;
    73 if(al<(endInt/100)){
    74 setTimeout(function(){showBackground(obj,endInt)},1);
    75 }
    76 }
    77 }
    78 //关闭窗口
    79 function closeWindow()
    80 {
    81 if(document.getElementById('back')!=null){
    82 document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    83 }
    84 if(document.getElementById('mesWindow')!=null){
    85 document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    86 }
    87 if(isIe){
    88 setSelectState('');
    89 }
    90 }
    91 </script>

    二、使用实例:

    Button1.Attributes.Add("onclick", "return showMessageBox(event,'友情提醒','数据提交中,请耐心等待',350,0);");
  • 相关阅读:
    learnyou 相关网站
    hdu 3038 How Many Answers Are Wrong
    hdu 3047 Zjnu Stadium 并查集高级应用
    poj 1703 Find them, Catch them
    poj 1182 食物链 (带关系的并查集)
    hdu 1233 还是畅通工程
    hdu 1325 Is It A Tree?
    hdu 1856 More is better
    hdu 1272 小希的迷宫
    POJ – 2524 Ubiquitous Religions
  • 原文地址:https://www.cnblogs.com/wonder315/p/1946115.html
Copyright © 2011-2022 走看看