基于bootstrap的提示弹窗实现
来源:互联网 发布:win7如何更改mac地址 编辑:程序博客网 时间:2024/05/20 23:34
最近一直在用bootstrap开发前端,也是比较苦恼。
开发中纠结于没有公共的标准提示弹窗,所以只能自己写一个(能力不是很好。。第一次造轮子,也不知道算不算轮子)
下面是代码:
1.初始化模态框dom 用时间戳作为 模态框 id。用于区分多个弹窗的情况
//初始化模态框var initWinModal = function(){//加入时间戳随机数id 区分模态框id,这样可以同时调用多个模态提示框pid += "-"+Date.now().toString(16);$(document.body).append('<div id="'+pid+'" class="modal fade bs-example-modal-sm" aria-hidden="true" data-backdrop="static"></div>');$("#"+pid).append('<div id="'+pid+'-body" class="modal-dialog modal-sm">'+'<div class="modal-content">'+'<div class="modal-header">'+ '<a id="'+pid+'-WinClose" class="close" data-dismiss="modal">'+_CONST.ualertContent.closeBtn+'</a>'+ '<h3 class="mah3">'+_CONST.ualertContent.title+'</h3>'+ '</div>'+ '<div id="'+pid+'-content" class="modal-body mabody">'+ '</div>'+ '<div class="modal-footer mafooter">'+ '<a id="'+pid+'-bSure" data-toggle="modal" data-dismiss="modal" class="btn mabun">'+_CONST.ualertContent.sureCn+'</a>'+ '<a id="'+pid+'-bClose" href="#" data-dismiss="modal" class="btn mabun">'+_CONST.ualertContent.closeCn+'</a>'+ '</div>'+ ' </div>'+'</div>');initDomVar();initContentBindButton();};
2.弹窗按钮绑定,
//初始化提示内容,绑定弹窗控件var initContentBindButton = function(){//初始化提示内容if(content === undefined || content === null){content = "";}getDom.bmaContent().html("<p>"+content+"</p>");//初始化按钮事件//确定按钮getDom.bmaButtonSure().unbind('click');getDom.bmaButtonSure().on('click',function(){_CONST.alertClickFlag = '0';});//窗口x关闭按钮getDom.bmaButtonWinClose().unbind('click');getDom.bmaButtonWinClose().on('click',function(){_CONST.alertClickFlag = '1';});//关闭按钮getDom.bmaButtonClose().unbind('click');getDom.bmaButtonClose().on('click',function(){_CONST.alertClickFlag = '1';});//隐藏窗口事件getDom.bMsgAlert().off('hidden.bs.modal');getDom.bMsgAlert().on('hidden.bs.modal', function(event) {//移除domgetDom.bMsgAlert().remove();if(_CONST.alertClickFlag === '0'){if(scb&&typeof(scb) === 'function'){scb();}}else if(_CONST.alertClickFlag === '1'){if(ccb&&typeof(ccb) === 'function'){ccb();}} });};
最后是弹窗呈现
之前遇到了模态框多层嵌套的问题,网上找了大神的方法。而后我自己又做了部分改进(原贴地址再贴一遍:http://blog.csdn.net/k358971707/article/details/71908862)
改进地方是遍历后再多加一个属性做为分层区分:
//遍历排序模态框 用layer 区分模态框层 $('.modal.in').each(function(index) { var $modal = $(this); var layer = $modal.attr('layer'); if(!layer||layer === undefined){ $modal.attr('layer', $('.modal.in').length); } $modal.css('zIndex', modalZIndex+(parseFloat($modal.attr('layer')))); });
//遍历排序模态框遮罩 用layer 区分模态框层 $('.modal-backdrop.in').each(function(index) { $modalbackdrop = $(this); var layer = $modalbackdrop.attr('layer'); if(!layer||layer === undefined){ $modalbackdrop.attr('layer', $('.modal-backdrop.in').length-1); } $modalbackdrop.addClass('hidden').css('zIndex', modalZIndex+(parseFloat($modalbackdrop.attr('layer')))); if(index === $('.modal-backdrop.in').length-1){ $modalbackdrop.removeClass('hidden'); } });
最后附上样例:
阅读全文
0 0
- 基于bootstrap的提示弹窗实现
- 基于bootstrap + velocity的分页实现
- 基于bootstrap + velocity的分页实现
- 基于Bootstrap右键菜单的简单实现
- 基于Bootstrap的多级表格实现
- 基于bootstrap实现分页
- bootstrap的tooltip提示
- jquery,bootstrap实现的用户名片信息提示
- CSS3实现Bootstrap的tooltip动画提示效果
- jquery,bootstrap实现的用户名片信息提示
- 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
- 基于jQuery、Bootstrap实现的仿知乎前端动态列表效果
- 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
- 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
- 基于Bootstrap框架的图片轮播实现
- 基于bootstrap的分页插件bootstrap-paginator
- 基于bootstrap的日期插件bootstrap-datetimepicker
- 基于bootstrap的select插件--bootstrap-select
- 攻击多个目标
- Ubuntu 常用软件安装和配置
- Maven之阿里云镜像仓库-yellowcong
- 基于SDP的提议/应答(offer/answer)模型简介
- Spring Boot搭建web服务
- 基于bootstrap的提示弹窗实现
- [leetcode] 112. Path Sum
- Use Cases for SIP and SDP Offer/Answer
- 判断字符串是否为空
- Maven——简介、安装(win10x64)
- poj2104 K-th Number (主席树无修改)
- Servlet运行原理及404、500、405异常原因和解决方法总结
- 不值一提的计算机基础教程-3-处理器
- spring 基础上