手机移动端alert替换方案

时间:2021-08-05 14:21:25
//alert
;(function () {
var AlertBox = function (options){
this.defaults = {
title:"",
callback:null
},
this.options = $.extend({}, this.defaults, options);
};
AlertBox.prototype = {
constructor: AlertBox,
init:function(){
var teml = "";
teml=teml+'<div id="alertbox">';
teml=teml+' <p id="msgA">'+this.options.title+'</p>';
teml=teml+'</div>';
if($("#alertbox").length===0){
$("body").append(teml);
}else{
$("#alertbox>#msgA").html(this.options.title);
}
$("#alertbox").stop(1,1).fadeIn();
setTimeout(function (){
$("#alertbox").stop(1,1).fadeOut();
}, 2000);
if(typeof (this.options.callback)=="function"){
this.options.callback();
}
}
};
$.AlertBox=function(options){
var alertBox = new AlertBox(options);
return alertBox.init();
};
}());