用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. 织梦后台添加友情链接的方法(flink标签)

    标记名称:flink[标签简介][功能说明]:用于获取友情链接,其对应后台文件为"includetaglibflink.lib.php".[适用范围]:全局标记,适用V55,V56 ...

  2. EasyUI combobox 加载JSON数据

    Action返回 JSON 格式如下: jsonResult = { total=7,rows=[ {TEXT=技术支持, ID=402894ca4419acf1014419b148a10000}, ...

  3. C++ 友元(系转载多人博客,添加个人见解)

    原文地址:http://blog.csdn.net/caroline_wendy/article/details/16916441 原文地址:http://www.cnblogs.com/CBDoct ...

  4. Pycharm使用中背景颜色和更改项目的Python版本

    一.背景颜色 颜色是每一个人都会去更改的,而且可以保护眼睛! 第二步: 选择图中画框的位置,便可以更改背景颜色! 二.项目版本的更改: python2 和 python3 有很大的不同,使用pytho ...

  5. js 获取URL中参数

    function getQueryString() { var result = location.search.match(new RegExp("[\?\&][^\?\& ...

  6. Log4net (Log for .net)

    Log4net (Log for .net) 开源的记录日志的组件,是从java的Log4J移植到.net 日志文件存放的位置 在项目新建“App_Code”和“App_Data”,该文件夹客户端无法 ...

  7. ZT 苍天助曹不助汉哪

    诸葛亮能夜观星象,但为什么在上方谷一役中,孔明没有测出突如其来的大雨,却高呼“苍天助曹不助汉哪”断送了自己的性命,这是为什么 谋事在人,成事在天.   雁过留影 3级 2011-04-18 天命不可违 ...

  8. PHP 字符串补0

    转自:https://www.cnblogs.com/bluebirds/archive/2016/11/22/6091099.html#undefined 概述:项目中经常会使用到在一串编码左边.右 ...

  9. 理解Underscore中的节流函数

    上一篇中讲解了Underscore中的去抖函数(_.debounced),这一篇就来介绍节流函数(_.throttled). 经过上一篇文章,我相信很多人都已经了解了去抖和节流的概念.去抖,在一段连续 ...

  10. Hibernate多对一关联关系

    两个持久化类.Customer 和 OrderForm Customer 类. package com.zcd.hibernate.manyToOne; public class Customer { ...