自定义确定框(confirm)
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)的更多相关文章
- 利用bootstrap的modal组件自定义alert,confirm和modal对话框
由于浏览器提供的alert和confirm框体验不好,而且浏览器没有提供一个标准的以对话框的形式显示自定义HTML的弹框函数,所以很多项目都会自定义对话框组件.本篇文章介绍自己在项目中基于bootst ...
- 在ASP.NET中引用自定义提示框
在html网页中自定义提示框 正文: 在一般的B/S架构中项目,与用户的交互信息是非常重要的.在一般的情况下,设计人员都在把用户信息呈现在html中,用div和span去弹出相关信息.对于一般的情况而 ...
- js确认框confirm()用法实例详解
先为大家介绍javascript确认框的三种使用方法,具体内容如下 第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认. ? 1 2 3 4 5 6 7 8 ...
- Qt之自定义搜索框
简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void ...
- 【Qt】Qt之自定义搜索框【转】
简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 简述 效果 细节分析 Coding 源码下载 效果 ...
- 【转】bootbox自定义dialog、confirm、alert样式,以及基本设置方法setDefaults中可用参数
<html> <head> <meta charset="utf-8"> <meta name="viewport" ...
- Android自定义View——自定义搜索框(SearchView)
Android自定义View——自定义搜索框(SearchView) http://www.apkbus.com/android-142064-1-1.html
- Xamarin Android自定义文本框
xamarin android 自定义文本框简单的用法 关键点在于,监听EditText的内容变化,不同于java中文本内容变化去调用EditText.addTextChangedListener(m ...
- CSS学习笔记三:自定义单选框,复选框,开关
一点一点学习CCS,这次学习了如何自定义单选框,复选框以及开关. 一.单选框 1.先写好body里面的样式,先写几个框 <body> <div class="radio-1 ...
- bootStrap-table服务器端后台分页的使用,以及自定义搜索框的实现,前端代码到数据查询超详细讲解
关于分页,之前一直纯手写js代码来实现,最近又需要用到分页,找了好多最终确定bootstrap-table,正好前端页面用的是bootstrap. 首先下载BootStrap-table的js和CSS ...
随机推荐
- mysql之备份表和备份数据库
备份表 1.首先创建一个与原来一样的表 create table score2 like score; ###like就是将score表的结构拷贝过来,但是它并不执行数据:也就是说执行完上面的语句之后 ...
- LUOGU P3355 骑士共存问题(二分图最大独立集)
传送门 因为骑士只能走"日"字,所以一定是从一个奇点到偶点或偶点到奇点,那么这就是一张二分图,题目要求的其实就是二分图的最大独立集.最大独立集=n-最大匹配. #include&l ...
- Python学习day19-常用模块之re模块
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习day18-常用模块之NumPy
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- 安卓自定义View进阶-Canvas之画布操作 转载
安卓自定义View进阶-Canvas之画布操作 转载 https://www.gcssloop.com/customview/Canvas_Convert 本来想把画布操作放到后面部分的,但是发现很多 ...
- React学习整理
React介绍 React设计思想及其独特,属于革命性创新,性能出众,代码逻辑却非常简单. 库(library):小而巧,库只提供了特定的api.优点是船小好调头,可以很方便的从一个库切换到另外的库, ...
- [转]WPF的Presenter(ContentPresenter)
这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...
- iTerm2配色和去掉profile提示框
效果: 配色方案代码地址: https://github.com/mbadolato/iTerm2-Color-Schemes 点击最右边的绿色区域,再点击 “import”, 打开刚下载解压好的文 ...
- PHP--时间搜索插件封装
/** * 时间搜索插件封装 * anthor qinpeizhou * @param $timeset 时间格式 * @param $time sql语句中所需要搜索的time字段名称 * @par ...
- 【Redis缓存机制】1.Redis介绍和使用场景
(1)持久化数据库的缺点平常我们使用的关系型数据库有Mysql.Oracle以及SqlServer等,在开发的过程中,数据通常都是通过Web提供的数据库驱动来链接数据库进行增删改查. 那么,我们日常使 ...