js原型方式自定义弹窗

function confirmAlert(){};

confirmAlert.prototype.make = function(title,content,falseTit,falseFn,trueTit,trueFn){
    this.content = content; //自定义弹窗的内容
    this.title = title || '温馨提示:'; //弹窗title
    this.falseBack = falseTit || "确定"; //确定
    this.falseFn = falseFn || denglu(); //点击确定的回调函数
    this.trueBack = trueBack || "取消"; //取消
    this.trueFn = trueFn || closealert(); //点击取消的回调函数
    var self = this;
    var div = document.createElement('div');
    div.setAttribute('id','alert-box')
    var iframe = "<div class='cover-layer'></div>"
        + "<div class='alert-box' style='width: 447px;'>"
        + "<div class='alert-th'>" + this.title + "<i class='icon-error' οnclick='closeAlert()'><img src='http://huahan.oss-cn-hangzhou.aliyuncs.com/icon/alert-error.png?t=1,x-oss-process=image/resize,m_fill,h_18,w_18 '/></i></div>"
        + "<div class='alert-td' style='height: 230px;'>"
        +"<div class='alert-text' style='height: 120px; top: 26%;text-align: center;padding-top:80px;line-height:30px;'>" + this.content + "</div>"
        +"<div class='btn-con btn-l' οnclick='"+this.falseFn+"' >"+this.falseBack+"</div><div class='btn-con btn-r' οnclick='"+this.trueFn+"'>"+this.trueBack+"</div>"
        + "</div>"
        +"</div>";
    var body = document.getElementsByTagName('body')[0];
    div.innerHTML = iframe;
    body.appendChild(div);
}
//关闭弹窗
confirmAlert.prototype.close = function(){
    var body = document.getElementsByTagName('body')[0];
    var div = document.getElementById('alert-box');
    body.removeChild(div);
    window.clearTimeout(set_time);
};


var confirmalerts = new confirmAlert();
//点击关闭
function closealert(){
    confirmalerts.close();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值