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. pure-Python PDF library

    # -*- coding: utf-8 -*- # # vim: sw=4:expandtab:foldmethod=marker # # Copyright (c) 2006, Mathieu Fe ...

  2. 二分图——多重匹配模板hdu1669

    好像多重匹配一般是用网络流来做的.. 这是匈牙利算法的模板:lim是每个组的上界 思路是每个组都可以匹配lim个点,那么当点x遇到的组匹配的点数还没有超过lim时,直接匹配即可 如果已经等于了lim, ...

  3. swoole是如何实现任务定时自动化调度的?

    https://www.muzilong.cn/article/117 开发环境 环境:lnmp下进行试验. 框架:laravel5 问题描述 这几天做银行对帐接口时,踩了一个坑,具体需求大致描述一下 ...

  4. VS2010-MFC(MFC应用程序框架分析)

    转自:http://www.jizhuomi.com/software/145.html 一.SDK应用程序与MFC应用程序运行过程的对比 程序运行都要有入口函数,在之前的C++教程中都是main函数 ...

  5. vue 实现单选框

    参考:https://blog.csdn.net/qq_42221334/article/details/81630634 效果: vue: <template> <div> ...

  6. css 阴影设置box-shadow

    box-shadow: 1px 2px 5px 6px #888888 inset 1px: 必须,水平阴影的位置, 负值为左 2px: 必须,垂直阴影的位置, 负值为上; 5px: 可选,模糊距离; ...

  7. vue页面刷新数据丢失问题

    参考: https://blog.csdn.net/aliven1/article/details/80743470          https://blog.csdn.net/liang37712 ...

  8. 同一服务器不同域名session共享

    Tomcat下,不同的二级域名之间或根域与子域之间,Session默认是不共享的,因为Cookie名称为JSESSIONID的Cookie根域是默认是没设置 的,访问不同的二级域名,其Cookie就重 ...

  9. xlwt/xlwt/Style.py excel样式源文件

    from __future__ import print_function # -*- coding: windows-1252 -*- from . import Formatting from . ...

  10. Hibernate通用Dao

    1. 接口 package com.coder163.main.dao; import org.hibernate.criterion.DetachedCriteria; import java.io ...