提示信息 alert

js代码

function alertbox(option) {

    var thisel = this;
    thisel.mergeJsonObject = function (jsonbject1, jsonbject2) {
        var resultJsonObject = {};
        var attr;
        for (attr in jsonbject1) {
            resultJsonObject[attr] = jsonbject1[attr];
        }
        for (attr in jsonbject2) {
            resultJsonObject[attr] = jsonbject2[attr];
        }

        return resultJsonObject;
    };
    thisel.o = {
        successMsg: '操作成功',
        errMsg: '操作失败',
        autoClose: '1' //是否自动关闭
        //resize: { width: 320, height: 240, quality: 90 }
    };
    //合并配置
    thisel.o = thisel.mergeJsonObject(thisel.o, option);

    thisel.createHtml = function () {
        var htmlbox = $("body");
        htmlbox.append("<div class=\"y-cue\" >" + "</div>");
    };

    function close() {
        //alert('dd');
        var htmlbox = $("body");
        var box = htmlbox.find(".y-cue");
        box.hide();
    }

    thisel.showsuccess = function () {
        var htmlbox = $("body");
        var box = htmlbox.find(".y-cue");
        box.html(thisel.o.successMsg);
        if (thisel.o.autoClose == '0') {
            box.append("<div><a href=\"javascript:void(0);\" id=\"aalertClose\">关闭</a></div>");
            $("#aalertClose").bind("click", function () {
                close();
            });
            box.show();
        } else {
            box.fadeIn("fast");
            setTimeout(function () {
                box.fadeOut("fast");
            }, 500);
        }
    };

    thisel.showerr = function () {
        var htmlbox = $("body");
        var box = htmlbox.find(".y-cue");
        box.html(thisel.o.errMsg);
        box.fadeIn("fast");
        setTimeout(function () {
            box.fadeOut("fast");
        }, 500);
    };
    thisel.warnerr = function (warnmsg) {
        var htmlbox = $("body");
        var box = htmlbox.find(".y-cue");
        box.html(warnmsg);
        box.fadeIn("fast");
        setTimeout(function () {
            box.fadeOut("fast");
        }, 1000);
    };

    thisel.hide = function () {
        setTimeout(function () {
            var htmlbox = $("body");
            var box = htmlbox.find(".y-cue");
            box.fadeOut("fast");
        }, 500);
    };

    thisel.showandredirct = function (url) {
        var htmlbox = $("body");
        var box = htmlbox.find(".y-cue");
        box.html(thisel.o.successMsg);
        box.fadeIn("fast");
        setTimeout(function () {
            box.fadeOut("fast");
            if (url) {
                window.location = url;
            } else {
                window.location = window.location;
            }
        }, 1000);
    };


    //初始化上传组建
    thisel.create = function () {
        thisel.createHtml();
    };


}

调用时

   var proup = null;
        $(function () {
            proup = new alertbox();
            proup.create();
        }); /// <summary>添加操作</summary>

 

posted on 2015-01-06 13:02  利利乐园  阅读(204)  评论(0编辑  收藏  举报