複製程式碼 程式碼如下: <br>function position(elem,l,t){<br> var isIE6 = !-[1,] && !window.XMLHttpRequest;<br> if(isIE6){<br> var style = elem.style,<br> dom = '(document.documentElement)',<br> left = l - document.documentElement.scrollLeft,<br> top = t - document.documentElement.scrollTop;<br> style.position = 'absolute';<br> style.removeExpression('left');<br> style.removeExpression('top');<br> style.setExpression('left', 'eval(' + dom + '.scrollLeft + ' + left + ') + "px"');<br> style.setExpression('top', 'eval(' + dom + '.scrollTop + ' + top + ') + "px"');<br> }else{<br> elem.style.position = 'fixed';<br> }<br>} <br>function scscms_alert(msg,sign,ok,can){<br> var c_=false;//是否已经关闭窗口,解决自动关闭与手动关闭冲突<br> sign=sign||"";<br> var s="<div id='mask_layer'></div><div id='scs_alert'><div id='alert_top'></div><div id='alert_bg'><table width='260' align='center' border='0' cellspacing='0' cellpadding='1'><tr>";<br> if (sign!="")s+="<td width='45'><div id='inco_"+sign+"'></div></td>";<br> s+="<td id='alert_txt'>"+msg+"</td></tr></table>";<br> if (sign=="confirm"){<br> s+="<a href='javascript:void(0)' id='confirm_ok'>确 定</a><a href='javascript:void(0)' id='confirm_cancel'>取 消</a>";<br> }else{<br> s+="<a href='javascript:void(0)' id='alert_ok'>确 定</a>"<br> }<br> s+="</div><div id='alert_foot'></div></div>";<br> $("body").append(s);<br> $("#scs_alert").css("margin-top",-($("#scs_alert").height() /2) "px"); //使其垂直居中<br> $("#scs_alert").focus(); //取得焦點,以防回車後無法觸發函數<br> position(document.getElementById ('mask_layer'),0,0);<br> position(document.getElementById('scs_alert'),$(window).width()/2,$(window).height()/2);<br> if (typeof can == "number"){<br> //定時關閉提示<br> setTimeout(function(){ } <br> function close_info(){<br> //關閉提示視窗<br> if(!c_){<br> $ ("#scs_alert").remove();<br> $(this).remove();<br> }<br> }<br> $(" #alert_ok").click(function(){<br> close_info();<br> if(typeof(ok)=="function"))(); close_info();<br> if(typeof(ok)=="function"))(); close_info();<br> if(typeof(can)=="function")can();<br>{p. <br> e = e||event;<br> close_info();<br> code == 32){if (typeof(ok)=="function")ok()}<br> if (code == 27){if(typeof(can)=="function")can()} <br>="function")can()} <br> if (document.attachEvent)<br> document.attachEvent("onkeydown", modal_key • Listingo. , modal_key, true) ;<br>}<br>//====================================以下為測試函數=======================================//<br>function test1(){<br> scscms_alert("預設提示訊息");<br>}<br>function test2(){<br> scscms_alert("成功提示訊息","ok");<br> {<br> scscms_alert("成功提示後回呼函數","ok",function(){alert("回呼成功! ")});<br>}<br>function test4(){<br> scscms_alert("失敗提示訊息","error");<br>}<br>function test5(){<br> sc "失敗提示訊息","error",function(){alert("喔!no!")});<br>}<br>function test6(){<br> scscms_alert("警告提示訊息"," warn");<br>}<br>function test7(){<br> scscms_alert("警告提示訊息","warn",function(){alert("喔!警告!")});<br> }<br>function test8(){<br> scscms_alert("您喜歡此資訊提示嗎?","confirm",function(){<br> scscms_alert("您選擇了喜歡,謝謝!" );<br> },function(){<br> scscms_alert("您選擇了不喜歡,汗!","error");<br> {function }); scscms_alert("本資訊3秒後自動關閉","ok",",3);<br>}<br>function test10(){<br> scscms_alert("詢問資訊定時關閉訊息提示資訊, 3秒後自動關閉,無取消時回呼函數.不建議使用。 ><br><br><br> </div>