演示地址:
http://runjs.cn/detail/miwszbne
分享说明:
第N次造轮子了,只为最简单的调用,jquery模拟alert和confirm的弹窗插件
调用方法:
$.alert('your message');
$.alert('your message',function(){
$.alert('click ok button')
});
$.confirm('your message');
$.confirm('your message',function(result){
if(result){
$.alert('click ok button')
}else{
$.alert('click cancel button')
}
})
为了调用方便,直接将css样式写在了js中,兼容性方面只测试了IE8和chrome以及safari,都还可以。
IE8没问题想必其他现代浏览器应该也是OK的。
(function ($) {
$.extend({
_isalert:0,
alert:function(){
if(arguments.length){
$._isalert=1;
$.confirm.apply($,arguments);
}
},
confirm:function(){
var args=arguments;
if(args.length&&(typeof args[0] == 'string')&&!$('#alert_overlay').length){
if(!$('#alert_style').length) $('body').append('');
var dialog=$(''+args[0]+'');
if($._isalert) dialog.find('.alert_btn_cancel').hide();
dialog.on('contextmenu',function(){
return !1;
}).on('click','.alert_btn_ok',function(){
dialog.remove();
if(typeof args[1]=='function') args[1].call($,!0);
}).on('click','.alert_btn_cancel',function(){
dialog.remove();
if(typeof args[1]=='function') args[1].call($,!1);
}).appendTo('body');
}
$._isalert=0;
}
});
})($);
以上所述就是本文的全部内容了,希望大家能够喜欢。










