手机移动端alert替换方案

//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();    
    };
}()); 

 

posted on 2015-07-09 17:41  青岛米柚  阅读(734)  评论(0编辑  收藏  举报