用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()'>&times;</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工具封装的更多相关文章

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

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

  2. 15 JavaScript弹窗(警告框alert、确认框confirm、提示框Promt)

    警告框:window.alert().通常用于确认用户可以得到某些信息 <body> <script type="text/javascript" charset ...

  3. element 确认框 confirm 的写法

    this.confirm('内容', '标题', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'success', callbac ...

  4. JQueryUI确认框 confirm

    $(function(){ $('#AlertMsg').dialog({ autoOpen: false, width: 300, modal: true, position: 'center', ...

  5. [转]js中confirm实现执行操作前弹出确认框的方法

    原文地址:http://www.jb51.net/article/56986.htm 本文实例讲述了js中confirm实现执行操作前弹出确认框的方法.分享给大家供大家参考.具体实现方法如下: 现在在 ...

  6. Android 学习笔记之AndBase框架学习(二) 使用封装好的进度框,Toast框,弹出框,确认框...

    PS:渐渐明白,在实验室呆三年都不如在企业呆一年... 学习内容: 1.使用AbActivity内部封装的方法实现进度框,Toast框,弹出框,确认框...   AndBase中AbActivity封 ...

  7. Vue使用Promise自定义confirm确认框组件

    使用Promise模拟浏览器确认框,可自定义标题,内容,按钮文字和类型 参数名 类型 说明 title String 标题 content String 内容 yesBtnText String 确认 ...

  8. ABP的确认框

    使用之前,是需要添加对abp.sweet-alert.js的引用,否则就无法正常使用. 确认框 abp.message.info('some info message', 'some optional ...

  9. WPF 提示框、确认框、确认输入框

    1.提示框 分为提示.异常.失败.成功几种类型 方法: /// <summary> /// 弹出提示 /// 标题:提示 /// </summary> /// <para ...

随机推荐

  1. 利用setTimeoutc处理javascript ajax请求超时

    用过jquery的人都知道里面的$.ajax能设置超时处理及各种错误的抛出,确实好用.原生的js没有对应的方法,还得写各种兼容.在实际运用中,不管请求是否成功都应该做容错处理, 不然用户不知道到底发生 ...

  2. jquery根据id取不到textarea对象,无法给textarea赋值

    小编定义了一个textarea控件,却无法根据id取到textarea对象并赋值. 经过实验,得出了原因.代码如下: <!DOCTYPE html><html><head ...

  3. hdu 1087 Super Jumping! Jumping! Jumping!(最大上升子序列和)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  4. c# 利用反射 从json字符串 动态创建类的实例 并动态为实例成员赋值

    转自 http://hi.baidu.com/wjinbd/item/c54d43d998beb33be3108fdd 1 创建自己要用的类 class stu { string _name; int ...

  5. androidcookie

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { webSettings.setAllowFileAccessFrom ...

  6. 微软Azure虚拟机备份服务在中国发布

    近期,Azure虚拟机备份服务在微软智能云上发布. 相关功能阐述: Azure IaaS虚拟机备份服务针对Windows操作系统,提供了应用一致性的备份技术:同时针对Linux操作系统,提供了文件系统 ...

  7. mongodb 3.4复制集详解

    1关闭数据库,打开三个mongodb数据库数据库实例 rs.printReplicationInfo() 2:原理 主库能够进行读写操作,一个复制集群只能有一个活跃的主库 一般情况下复制可以分为好几种 ...

  8. Oracle数据库从入门到精通 多表查询知识以及范例

    视频课程:李兴华 Oracle从入门到精通视频课程 学习者:阳光罗诺 视频来源:51CTO学院 总体内容: 多表查询的意义以及基本问题. 表的连接查询 SQL:1999语法标准对多表查询的支持. 数据 ...

  9. deepin ubuntu等创建桌面快捷方式

    Linux网上下载软件一般只会有.sh结尾执行程序.并不会像商店下载一样自动创建桌面图标.此时需要自行进行编辑. #创建一个桌面图标后缀名为.desktop touch myDesktop.deskt ...

  10. 实战开发一个Nginx扩展 (Nginx Module)

    repo地址 https://github.com/wujunze/nginx-http-echo-module nginx_module_echo 使用echo指令输出一个字符串 Nginx 版本 ...