Copy code The code is as follows: <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"); //Make it vertically centered <br> $("#scs_alert").focus(); //Get the focus in case the function cannot be triggered after carriage return <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> //Close prompts regularly<br> setTimeout(function(){<br> close_info();<br> },can*1000);<br> } <br> function close_info(){<br> //Close the prompt window<br> if(!c_){<br> $("#mask_layer").fadeOut("fast",function(){<br> $ ("#scs_alert").remove();<br> . #alert_ok").click(function(){<br> close_info();<br> if(typeof(ok)=="function")ok();<br> });<br> $("# confirm_ok").click(function(){<br> close_info();<br> if(typeof(ok)=="function")ok();<br> });<br> $("#confirm_cancel ").click(function(){<br> <br> e = e||event;<br> close_info();<br> var code = e.which||event.keyCode;<br> if (code == 13 || code == 32){if (typeof(ok)=="function")ok()}<br> if (code == 27){if(typeof(can)=="function")can()} <br> }<br> / /Bind the Enter and ESC keys<br> if (document.attachEvent)<br> document.attachEvent("onkeydown", modal_key);<br> else<br> document.addEventListener("keydown", modal_key, true) ;<br>}<br>//======================================The following is the test function =======================================//<br>function test1(){<br> scscms_alert("Default prompt message");<br>}<br>function test2(){<br> scscms_alert("Success prompt message", "ok");<br>}<br>function test3() {<br> scscms_alert("Callback function after successful prompt","ok",function(){alert("Callback successful! ")});<br>}<br>function test4(){<br> scscms_alert("Failure message","error");<br>}<br>function test5(){<br> scscms_alert( "Failure message","error",function(){alert("Oh! no!")});<br>}<br>function test6(){<br> scscms_alert("Warning message"," warn");<br>}<br>function test7(){<br> scscms_alert("Warning message","warn",function(){alert("Oh! Warning!")});<br> }<br>function test8(){<br> scscms_alert("Do you like this information prompt?","confirm",function(){<br> scscms_alert("You chose to like it, thank you!","ok" ; <br> scscms_alert("This message will automatically close after 3 seconds","ok","",3);<br>}<br>function test10(){<br> scscms_alert("Ask for the message to be closed regularly, Automatically close after 3 seconds, no callback function. Not recommended. ","confirm",function(){alert("Confirm callback!")},3);<br>}<br></ script><br><br><br> </div>