确认框,confirm工具封装
用bootstrap封装了个确认框工具
效果如下

代码如下:
/**
* 以模态窗做确认框的函数,title为标题栏内容,body为消息体,yesFun为点击确认按钮后执行的函数,执行后会执行关闭并删除该模态窗的函数
* 该模态窗只有模态窗
* @param:title:提示标题
* @param:body:提示内容
* @param:yesFun:点击确定后将执行的js函数
*/
function modalInit(title, body, yesFun) {
var modal = "<div class='modal fade simple-modal' tabindex='-1' role='dialog' aria-hidden='true'"
+ "style='position:fixed;z-index:3000;max-width:325px;margin-left:auto;margin-right:auto;top:30%'>"
+ "<div class='modal-dialog' style='width:auto'>"
+ "<div class='modal-content' style='width:auto'>"
+ "<div class='modal-header' style='padding:5px 10px;margin:4px;background-color:#eeeeee;width:auto'>"
+ "<button type='button' class='close' data-dismiss='modal' aria-hidden='true' onclick='closeSimpleModal()'>×</button>"
+ "<h4 class='modal-title' style='padding:2px 10px;'>" + title + "</h4>"
+ "</div>"
+ "<div class='modal-body text-warning text-center' style='padding:10px;font-size:16px;width:auto'>" + body + "</div>"
+ "<div class='modal-footer' style='padding:5px 10px;width:auto'>"
+ "<button type='button' class='btn btn-danger btn-sm' onclick='" + yesFun + ";closeSimpleModal()' style='margin:2px 5px'>确认</button>"
+ "<button type='button' class='btn btn-default btn-sm' data-dismiss='modal' onclick='closeSimpleModal()' style='margin:2px 5px'>取消</button>"
+ "</div></div></div>";
if ($('body').find('.simple-modal').length == 0) { //body中并没有任何没有被关掉的simple的模态窗
$('body').append(modal);
}
$('.simple-modal').modal('show'); //展示模态窗
$('body').unbind('click.mo')
setTimeout(function() {
$('body').bind('click.mo', function() {
$('.simple-modal').modal('hide');
$('.modal-backdrop').remove();
})
}, 200)
}
/**
* 点击取消或遮罩时候将执行的关闭确认框函数
*/
function closeSimpleModal() {
$('.simple-modal').remove();
$('.modal-backdrop').remove();
}
调用举例:
/**
* 展示详细中的删除user按钮点击函数
*/
function removeUser() {
var id = $('#user-detail-id').html();
modalInit('操作确认!!', "确认删除当前用户?", "removeUserSubmit(" + id + ")");//调用确认框
} /**
* 删除user按提交函数,确认框中点击确认后删除的提交的函数
*/
function removeUserSubmit(id) {
if (id != null && id != '' && typeof id != 'undefined') {
$.ajax({
type : 'POST',
url : local + "user/removeUserById.do",
data : {
id : id
},
async : true,
success : function(resultMap) {
if (resultMap.status == "success") { //成功则显示详细
$('#bottom-page-in').load(local + 'one/user/user-index.html');
$('#body #menu-jump-page').hide(300);
//lyhFloatTip("删除成功...正在刷新...");
} else {
//topTipModal("操作提示:", "<span class='text-warning'>" + resultMap.message + "</span>", 12000);
return null;
}
},
error : function(resultMap) {
console.error(resultMap);
}
});
} else {
//topTipModal("操作提示:", "<span class='text-warning'>删除操作传入的id有问题,请重试</span>", 12000);
}
}
以上
确认框,confirm工具封装的更多相关文章
- js确认框confirm()用法实例详解
先为大家介绍javascript确认框的三种使用方法,具体内容如下 第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认. ? 1 2 3 4 5 6 7 8 ...
- 15 JavaScript弹窗(警告框alert、确认框confirm、提示框Promt)
警告框:window.alert().通常用于确认用户可以得到某些信息 <body> <script type="text/javascript" charset ...
- element 确认框 confirm 的写法
this.confirm('内容', '标题', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'success', callbac ...
- JQueryUI确认框 confirm
$(function(){ $('#AlertMsg').dialog({ autoOpen: false, width: 300, modal: true, position: 'center', ...
- [转]js中confirm实现执行操作前弹出确认框的方法
原文地址:http://www.jb51.net/article/56986.htm 本文实例讲述了js中confirm实现执行操作前弹出确认框的方法.分享给大家供大家参考.具体实现方法如下: 现在在 ...
- Android 学习笔记之AndBase框架学习(二) 使用封装好的进度框,Toast框,弹出框,确认框...
PS:渐渐明白,在实验室呆三年都不如在企业呆一年... 学习内容: 1.使用AbActivity内部封装的方法实现进度框,Toast框,弹出框,确认框... AndBase中AbActivity封 ...
- Vue使用Promise自定义confirm确认框组件
使用Promise模拟浏览器确认框,可自定义标题,内容,按钮文字和类型 参数名 类型 说明 title String 标题 content String 内容 yesBtnText String 确认 ...
- ABP的确认框
使用之前,是需要添加对abp.sweet-alert.js的引用,否则就无法正常使用. 确认框 abp.message.info('some info message', 'some optional ...
- WPF 提示框、确认框、确认输入框
1.提示框 分为提示.异常.失败.成功几种类型 方法: /// <summary> /// 弹出提示 /// 标题:提示 /// </summary> /// <para ...
随机推荐
- for 循环的时候 append() 是移动不是复制
使用for 的时候,append() 不是复制,而是移动,只有最后一个元素才真正的append() 到了 解决办法: 1. 使用字符串: 2.使用clone();
- CentOS 7运维管理笔记(1)----设置默认启动模式为GUI模式或命令行模式
昨天在虚拟机中安装CentOS 7时选择了GNOME模式安装,开机默认进入GUI模式.网上搜找修改为默认命令行模式的方法,看到说修改 /etc/inittab文件,在最低下一行添加 但是 使用 cat ...
- 项目经验:GIS<MapWinGIS>建模第七天
终天完成了管网地图的附加功能..实现了了管网与地图结合
- 【阿里云产品公测】性能测试服务PTS的初步尝试
性能测试服务PTS,对于像我这样对测试毫无概念的新手来说,这服务真的太好了,使用简单,官方教程又明细,连我这样的新手一看都明白了怎样使用. _%GGl$kH 下面是我来简单尝试一下,更多功 ...
- How to solve problems
练习是为了帮助你成长 0.Don't panic! 1.What are the inputs? 2.What are the outputs? 3.Work through some example ...
- 利用NVM在系统中维护多个版本的nodejs
0. 背景 开发时可能同时进行多个项目,而这些项目所依赖的node版本又不是一样的.比如我现在的angular项目采用的node是8.9.3版本,而vue项目的vue-cli则依赖更高.由于ang ...
- 微软智能云Azure – 中国首家官方支持CoreOS的公有云
北京2016年6月24日, 在由中国开源软件推进联盟(COPU)主办, 开源社协办,微软赞助的“第十一届开源中国开源世界高峰论坛”上,微软亚太研发集团云计算高级总监梁戈碧女士正式对外宣布一个令人振奋的 ...
- 十个免费的 Web 压力测试工具
本文列举了是十个免费工具,可以用来进行Web的负载/压力测试的.这样你就可以知道你的服务器以及你的WEB应用能够扛得住多少的并发量,以及网站性能. 0. Grinder – Grinder是一个开源 ...
- CentOS 系统新装每次必看,直到背下。。
1.CentOS7 mini 修改网卡信息: vi /etc/sysconfig/network-scripts/ifcfg-ens192 ONBOOT = yes vi /etc/resolv.co ...
- January 25 2017 Week 4 Wednesday
In every triumph, there's a lot of try. 每个胜利背后都有许多尝试. There's a lot of try behind every success, and ...