重寫一下js的alert函數
2015-07-20 15:52
495 查看
$.Alert={ verticalOffset:-75,horizontalOffset:0, alert:function(msg,callback){ $.Alert._show(msg,'alert',function(result){if(callback)callback(result)}) } ,_show:function(msg,type,callback){ $.Alert._hide(); $.Alert._overlay('show'); $("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>'); //var pos=($.browser.msie&&parseInt($.browser.version)<=6)?'absolute':'fixed'; var pos='fixed'; $("#popup_container").css({position:pos,zIndex:99999,padding:0,margin:0}); $("#popup_message").html(msg.replace(/\n/g,'<br>')); //$("#popup_message").html($("#popup_message").text().replace(/\n/g,'<br />')); $("#popup_container").css({minWidth:$("#popup_container").outerWidth(),maxWidth:$("#popup_container").outerWidth()}); $.Alert._creat(); $(window).bind('resize',function(){$.Alert._creat()}); if(type=='alert'){ $("#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>'); $("#popup_ok").click(function(){$.Alert._hide();callback(true)}); $("#popup_ok").focus().keypress(function(e){if(e.keyCode==13||e.keyCode==27)$("#popup_ok").trigger('click')}); } } ,_hide:function(){ $("#popup_container").remove(); $.Alert._overlay('hide'); $(window).unbind('resize'); } ,_overlay:function(status){ switch(status){ 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; case'hide':$("#popup_overlay").remove();break } } ,_creat:function(){ var top=(($(window).height()/2) - ($("#popup_container").outerHeight()/2))+$.Alert.verticalOffset; var left=(($(window).width()/2) - ($("#popup_container").outerWidth()/2))+$.Alert.horizontalOffset; if(top<0)top=0; if(left<0)left=0; //if($.browser.msie&&parseInt($.browser.version)<=6)top=top+$(window).scrollTop(); $("#popup_container").css({top:top+'px',left:left+'px'}); $("#popup_overlay").height($(document).height()) } };window.alert=function(msg,callback){$.Alert.alert(msg,callback)};
相关文章推荐
- select2常用操作
- javascript为DOM元素设置样式
- 【阅读】《head first html5》第二章——javascript和DOM
- json2.js 的使用
- 使用js函数对select中的option排序后输出
- 使用Javascript来创建一个响应式的超酷360度全景图片查看幻灯效果
- jstring 和string char*之间的转换
- JavaScript学习要点(四)
- maven引入json-lib的正确方法
- 【W3s学JSON】JSON入门概念学习笔记 _W3school
- Angular.js学习笔记
- JS打乱数组最高效的方法
- javascript数组,创建,操作
- JSON-RPC轻量级远程调用协议介绍及使用
- json解析+GridView自适应布局+图片加载
- 点击弹出带有确定和取消选项的提示框
- js进阶
- javascript获取文件后缀名
- javascript 切换按钮改变div颜色
- javascript获取url各种信息