1、先引入 confirm.css

@charset "UTF-8";

lq-alert {
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .35);
position: fixed;
top:;
left:;
display: flex;
display: -webkit-flex;
justify-content: center;
align-items: center;
z-index:;
} alert-wrap {
width: 300px;
background: #fff;
border-radius: 5px;
overflow: hidden;
font: 300 20px "微软雅黑" !important;
} alert-content {
padding: 25px 40px;
font-weight: lighter;
font-size: 16px !important;
display: flex;
display: -webkit-flex;
justify-content: center;
align-items: center;
}
alert-btnbox {
height: 60px;
display: flex;
display: -webkit-flex;
justify-content: space-between;
align-items: center;
} alert-btn {
display: flex;
display: -webkit-flex;
justify-content: center;
align-items: center;
width: calc(50% - .5px);
height: 100%;
cursor: pointer;
color: #fff;
letter-spacing: 2px;
}
#lq-alert-canc-btn{
color: #D3D3D3;
border-top:1px solid #D3D3D3;
border-right:1px solid #D3D3D3;
}
#lq-alert-sure-btn{
color: #FF0000;
border-top:1px solid #D3D3D3;
border-right:1px solid #D3D3D3;
}
#alert-btn:active {
background: rgb(35, 106, 118);
border-top:1px solid #696969; } .alert-sure-btn {
width: 100%;
} .lq-alert-text-ipt {
box-sizing: border-box;
border: 1px solid #d3d3d3;
border-radius: 3px;
outline: none;
width: 100%;
height: 35px;
padding-left: 8px;
color: #696969;
font: 300 14px "微软雅黑";
}
alert-title {
display: flex;
display: -webkit-flex;
justify-content: center;
align-items: center;
text-align: center;
margin: 0 auto;
margin-top: 30px;
background: url(../images/smile.png) no-repeat center center;
background-size: cover;
width: 70px;
height: 70px;
}

2、引入confirm.js

;(function (window) {
let lqAlertView = function (options) {
// 定义属性
this.sureBtn = null;
this.cancelBtn = null;
this.textInput = null;
// 设置默认属性
this.configs = {
"type": "default",
"title": "",
"message": "",
"autoClose": 0,
"placeholder": "",
"cancelTitle": "离开",
"sureTitle": "再做一张",
"cancelCallBack": "",
"sureCallBack": ""
};
// 扩展默认属性
options && this.extend(this.configs, options);
// 初始化方法
this.init();
// 事件添加
this.sureBtn && this.addEvent(this.sureBtn, "click", this.btnClick.bind(this));
this.cancelBtn && this.addEvent(this.cancelBtn, "click", this.btnClick.bind(this));
document.body.style.cssText = "overflow: hidden;";
// 判断是否自动关闭
this.configs.autoClose && setTimeout(this.close, this.configs.autoClose);
}; lqAlertView.prototype = {
init: function () {
var config = this.configs,
alertHtmls = "";
switch (config.type) { case "confirm": {
alertHtmls =
"<lq-alert>" +
"<alert-wrap>" +
"<alert-title></alert-title>" +
"<alert-content>" + config.message + "</alert-content>" +
"<alert-btnbox>" +
"<alert-btn id='lq-alert-canc-btn'>" + config.cancelTitle + "</alert-btn>" +
"<alert-btn id='lq-alert-sure-btn'>" + config.sureTitle + "</alert-btn>" +
"</alert-btnbox>" +
"</alert-wrap>" +
"</lq-alert>";
} break;
}
document.body.insertAdjacentHTML("beforeend", alertHtmls);
this.sureBtn = document.getElementById("lq-alert-sure-btn");
this.cancelBtn = document.getElementById("lq-alert-canc-btn");
this.textInput = document.getElementById("lq-alert-text-ipt");
},
extend: function (oldObj, newObj) {
for(var key in newObj) {
oldObj[key] = newObj[key];
}
return oldObj;
},
addEvent: function(el, type, callBack) {
if (el.attachEvent) {
el.attachEvent('on' + type, callBack);
} else {
el.addEventListener(type, callBack, false);
}
},
btnClick: function (e) {
e = e || event;
var _this = this,
_tarId = e.target.id,
_configs = this.configs;
switch(_tarId) {
// 点击取消按钮
case "lq-alert-canc-btn":{
_configs.cancelCallBack && _configs.cancelCallBack();
_this.close();
// window.location.href
} break;
// 点击确认按钮
case "lq-alert-sure-btn": {
var text = _configs.type == "prompt" ? _this.textInput.value : "" ;
_configs.sureCallBack && _configs.sureCallBack(text);
_this.close();
}break;
} },
close: function () {
var alert = document.getElementsByTagName("lq-alert")[0];
document.body.removeChild(alert);
document.body.style.cssText = "overflow: auto;"; }
}; window.lqAlertView = lqAlertView;
})(window);

3、实例化使用

 new lqAlertView({
type: "confirm",
title: "",
message: "您还可以再寄出"+(2 - parseInt(data.data.num))+"张哦",//邀请函正在加紧制作中,
sureCallBack: function (e) {
var url = encodeURI("editPostcard.html");
window.location.href = url;
},
cancelCallBack: function (e) {
wx.closeWindow();
}
})

自定义确定框(confirm)的更多相关文章

  1. 利用bootstrap的modal组件自定义alert,confirm和modal对话框

    由于浏览器提供的alert和confirm框体验不好,而且浏览器没有提供一个标准的以对话框的形式显示自定义HTML的弹框函数,所以很多项目都会自定义对话框组件.本篇文章介绍自己在项目中基于bootst ...

  2. 在ASP.NET中引用自定义提示框

    在html网页中自定义提示框 正文: 在一般的B/S架构中项目,与用户的交互信息是非常重要的.在一般的情况下,设计人员都在把用户信息呈现在html中,用div和span去弹出相关信息.对于一般的情况而 ...

  3. js确认框confirm()用法实例详解

    先为大家介绍javascript确认框的三种使用方法,具体内容如下 第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认. ? 1 2 3 4 5 6 7 8 ...

  4. Qt之自定义搜索框

    简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void ...

  5. 【Qt】Qt之自定义搜索框【转】

    简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 简述 效果 细节分析 Coding 源码下载 效果 ...

  6. 【转】bootbox自定义dialog、confirm、alert样式,以及基本设置方法setDefaults中可用参数

    <html> <head> <meta charset="utf-8"> <meta name="viewport" ...

  7. Android自定义View——自定义搜索框(SearchView)

    Android自定义View——自定义搜索框(SearchView) http://www.apkbus.com/android-142064-1-1.html

  8. Xamarin Android自定义文本框

    xamarin android 自定义文本框简单的用法 关键点在于,监听EditText的内容变化,不同于java中文本内容变化去调用EditText.addTextChangedListener(m ...

  9. CSS学习笔记三:自定义单选框,复选框,开关

    一点一点学习CCS,这次学习了如何自定义单选框,复选框以及开关. 一.单选框 1.先写好body里面的样式,先写几个框 <body> <div class="radio-1 ...

  10. bootStrap-table服务器端后台分页的使用,以及自定义搜索框的实现,前端代码到数据查询超详细讲解

    关于分页,之前一直纯手写js代码来实现,最近又需要用到分页,找了好多最终确定bootstrap-table,正好前端页面用的是bootstrap. 首先下载BootStrap-table的js和CSS ...

随机推荐

  1. cycloneii LAB-wide signals

    8 available LAB-width signals - 2 clocks - 2 clock enables - 2 asynchronous clears // - 1 asynchrono ...

  2. sqlite3-入门日记4-实现C++类封装

    一.前言:   今天试了下如何用C++类实现接口封装,感觉蛮好 .用于封装的类主要有两个,SQLiteStatement类和SQLiteWrapper类,是一个老外写的.我看了下源码,主要是对C接口进 ...

  3. echarts高级

    常用,待续... ♣tooltip自动轮播 ♣ 实现数据自动轮播 原理:其实就是timeline,获取某几段(时间)的数据,然后隐藏timeline ♣ legend自动轮播 ♣ 左侧多字出省略号 f ...

  4. Linux 的文件和目录管理类命令

    文件和目录管理类的命令 目录: cd ~[username] ~:指定用户的家目录 cd -:回到上一次所在的目录 路径: 相对路径中: .:当前目录 ..:父目录 pwd: print workin ...

  5. Spring MVC(八)--控制器接受简单列表参数

    有些场景下需要向后台传递一个数组,比如批量删除传多个ID的情况,可以使用数组传递,数组中的ID元素为简单类型,即基本类型. 现在我的测试场景是:要从数据库中查询minId<id<maxId ...

  6. ssh连接Ubuntu之access denied

    解决方法是: 修改/etc/ssh/ssh_config文件, #PermitRootLogin prohibit-password改为PermitRootLogin yes 然后 PasswordA ...

  7. vue 打包后app.css,verondor.js文件过大

    参考:https://blog.csdn.net/feiyu_may/article/details/80987404         https://blog.csdn.net/qq_4199961 ...

  8. 使用Log4net把日志写入到SqlServer数据库

    1.官网URL: http://logging.apache.org/log4net/ 2.配置文件参照URL: http://logging.apache.org/log4net/release/c ...

  9. java linkedlist和arraylist添加元素时性能比较

  10. leetcode 1071 Greatest Common Divisor of Strings

    lc1071 Greatest Common Divisor of Strings 找两个字符串的最长公共子串 假设:str1.length > str2.length 因为是公共子串,所以st ...