【Wonder整理】防止重复提交并弹出半透明对话框

一、JavaScript代码:

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
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;width: " + 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='width:1px;'> " ;
44 if ( isShowClose == 1 )
45 {
46 html += " <input type='button' οnclick='closeWindow();' title='Close(关闭窗口)' style='height: 15px;width: 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;width: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); " );

转载于:https://www.cnblogs.com/wonder315/archive/2011/01/27/1946115.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值