//jquery信息提示弹出层插件 - 站长素材 function position(elem,l,t){ var isie6 = !-[1,] && !window.xmlhttprequest; if(isie6){ var style = elem.style, dom = '(document.documentelement)', left = l - document.documentelement.scrollleft, top = t - document.documentelement.scrolltop; style.position = 'absolute'; style.removeexpression('left'); style.removeexpression('top'); style.setexpression('left', 'eval(' + dom + '.scrollleft + ' + left + ') + "px"'); style.setexpression('top', 'eval(' + dom + '.scrolltop + ' + top + ') + "px"'); }else{ elem.style.position = 'fixed'; } } function scscms_alert(msg,sign,ok,can){ var c_=false;//是否已经关闭窗口,解决自动关闭与手动关闭冲突 sign=sign||""; var s="
"; if (sign!="")s+=""; s+="
"+msg+"
"; if (sign=="confirm"){ s+="确 定取 消"; }else{ s+="确 定" } s+="
"; $("body").append(s); $("#scs_alert").css("margin-top",-($("#scs_alert").height()/2)+"px"); //使其垂直居中 $("#scs_alert").focus(); //获取焦点,以防回车后无法触发函数 position(document.getelementbyid('mask_layer'),0,0); position(document.getelementbyid('scs_alert'),$(window).width()/2,$(window).height()/2); if (typeof can == "number"){ //定时关闭提示 settimeout(function(){ close_info(); },can*1000); } function close_info(){ //关闭提示窗口 if(!c_){ $("#mask_layer").fadeout("fast",function(){ $("#scs_alert").remove(); $(this).remove(); }); c_=true; } } $("#alert_ok").click(function(){ close_info(); if(typeof(ok)=="function")ok(); }); $("#confirm_ok").click(function(){ close_info(); if(typeof(ok)=="function")ok(); }); $("#confirm_cancel").click(function(){ close_info(); if(typeof(can)=="function")can(); }); function modal_key(e){ e = e||event; close_info(); var code = e.which||event.keycode; if (code == 13 || code == 32){if(typeof(ok)=="function")ok()} if (code == 27){if(typeof(can)=="function")can()} } //绑定回车与esc键 if (document.attachevent) document.attachevent("onkeydown", modal_key); else document.addeventlistener("keydown", modal_key, true); } //====================================以下为测试函数=======================================// //scscms_alert("默认提示信息"); //scscms_alert("成功提示信息","ok"); //scscms_alert("成功提示后回调函数","ok",function(){alert("回调成功!")}); //scscms_alert("失败提示信息","error"); //scscms_alert("失败提示信息","error",function(){alert("哦!no!")}); //scscms_alert("警告提示信息","warn"); //scscms_alert("警告提示信息","warn",function(){alert("哦!警告!")}); //function test8(){ // scscms_alert("您喜欢此信息提示吗?","confirm",function(){ // scscms_alert("您选择了喜欢,谢谢!","ok"); // },function(){ // scscms_alert("您选择了不喜欢,汗!","error"); // }); //} //scscms_alert("本信息3秒后自动关闭","ok","",3); //scscms_alert("询问信息定时关闭提示信息,3秒后自动关闭,无取消时回调函数.不推荐使用。","confirm",function(){alert("确定回调用!")},3);