重写一下js的alert函數

  1. $.Alert={  
  2.     verticalOffset:-75,horizontalOffset:0,  
  3.     alert:function(msg,callback){  
  4.         $.Alert._show(msg,'alert',function(result){if(callback)callback(result)})  
  5.     }  
  6.     ,_show:function(msg,type,callback){  
  7.         $.Alert._hide();  
  8.         $.Alert._overlay('show');  
  9.         $("BODY").append('<div id="popup_container" style="font-family:Arial,sans-serif;line-height:25px;font-size:12px;min-width:300px;max-width:600px;border:1px solid #ddd;color:#000;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;background-color:#fff"><div id="popup_content" style="margin:0;padding:10px"><div id="popup_message"></div></div></div>');  
  10.         //var pos=($.browser.msie&&parseInt($.browser.version)<=6)?'absolute':'fixed';  
  11.         var pos='fixed';  
  12.         $("#popup_container").css({position:pos,zIndex:99999,padding:0,margin:0});  
  13.         $("#popup_message").html(msg.replace(/\n/g,'<br>'));  
  14.         //$("#popup_message").html($("#popup_message").text().replace(/\n/g,'<br />'));  
  15.         $("#popup_container").css({minWidth:$("#popup_container").outerWidth(),maxWidth:$("#popup_container").outerWidth()});  
  16.         $.Alert._creat();  
  17.         $(window).bind('resize',function(){$.Alert._creat()});  
  18.         if(type=='alert'){  
  19.             $("#popup_message").after('<div style="text-align:center;margin-top:20px"><button id="popup_ok" style="width:70px;border:1px solid #444;color:#000;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px">確認</button></div>');  
  20.             $("#popup_ok").click(function(){$.Alert._hide();callback(true)});  
  21.             $("#popup_ok").focus().keypress(function(e){if(e.keyCode==13||e.keyCode==27)$("#popup_ok").trigger('click')});  
  22.         }  
  23.     }  
  24.     ,_hide:function(){  
  25.         $("#popup_container").remove();  
  26.         $.Alert._overlay('hide');  
  27.         $(window).unbind('resize');  
  28.     }  
  29.     ,_overlay:function(status){  
  30.         switch(status){  
  31.             case'show':$.Alert._overlay('hide');$("BODY").append('<div id="popup_overlay"></div>');$("#popup_overlay").css({position:'absolute',zIndex:99998,top:'0px',left:'0px',width:'100%',height:$(document).height(),backgroundColor:'#000',opacity:0.7});break;  
  32.             case'hide':$("#popup_overlay").remove();break  
  33.         }  
  34.     }  
  35.     ,_creat:function(){  
  36.         var top=(($(window).height()/2) - ($("#popup_container").outerHeight()/2))+$.Alert.verticalOffset;  
  37.         var left=(($(window).width()/2) - ($("#popup_container").outerWidth()/2))+$.Alert.horizontalOffset;  
  38.         if(top<0)top=0;  
  39.         if(left<0)left=0;  
  40.         //if($.browser.msie&&parseInt($.browser.version)<=6)top=top+$(window).scrollTop();  
  41.         $("#popup_container").css({top:top+'px',left:left+'px'});  
  42.         $("#popup_overlay").height($(document).height())  
  43.     }  
  44. };window.alert=function(msg,callback){$.Alert.alert(msg,callback)}; 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值