bootstrap 重写JS的alert、comfirm函数
原理是使用bootstrap的Modal插件实现。
一、在前端模板合适的地方,加入Modal展现div元素。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!-- system modal start --> < div id = "ycf-alert" class = "modal" > < div class = "modal-dialog modal-sm" > < div class = "modal-content" > < div class = "modal-header" > < button type = "button" class = "close" data-dismiss = "modal" >< span aria-hidden = "true" >×</ span >< span class = "sr-only" >Close</ span ></ button > < h5 class = "modal-title" >< i class = "fa fa-exclamation-circle" ></ i > [Title]</ h5 > </ div > < div class = "modal-body small" > < p >[Message]</ p > </ div > < div class = "modal-footer" > < button type = "button" class = "btn btn-primary ok" data-dismiss = "modal" >[BtnOk]</ button > < button type = "button" class = "btn btn-default cancel" data-dismiss = "modal" >[BtnCancel]</ button > </ div > </ div > </ div > </ div > <!-- system modal end --> |
二、在前端模板的公共模块,找合适的地方引入bootstrap
1
2
3
4
|
< link rel = "stylesheet" href = "__TPL__/css/photoswipe.css" > < script type = "text/javascript" src = "__PUBLIC__/js/jquery.min.js" ></ script > < script src = "__PUBLIC__/bootstrap/js/bootstrap.min.js" ></ script > |
三、在JS的comon层,加入重写语句。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
//封装alert、confirm window.Modal = function () { var reg = new RegExp( "\\[([^\\[\\]]*?)\\]" , 'igm' ); var alr = $( "#ycf-alert" ); var ahtml = alr.html(); var _alert = function (options) { alr.html(ahtml); // 复原 alr.find( '.ok' ).removeClass( 'btn-success' ).addClass( 'btn-primary' ); alr.find( '.cancel' ).hide(); _dialog(options); return { on: function (callback) { if (callback && callback instanceof Function) { alr.find( '.ok' ).click( function () { callback( true ) }); } } }; }; var _confirm = function (options) { alr.html(ahtml); // 复原 alr.find( '.ok' ).removeClass( 'btn-primary' ).addClass( 'btn-success' ); alr.find( '.cancel' ).show(); _dialog(options); return { on: function (callback) { if (callback && callback instanceof Function) { alr.find( '.ok' ).click( function () { callback( true ) }); alr.find( '.cancel' ).click( function () { callback( false ) }); } } }; }; var _dialog = function (options) { var ops = { msg: "提示内容" , title: "操作提示" , btnok: "确定" , btncl: "取消" }; $.extend(ops, options); // console.log(alr); var html = alr.html().replace(reg, function (node, key) { return { Title: ops.title, Message: ops.msg, BtnOk: ops.btnok, BtnCancel: ops.btncl }[key]; }); alr.html(html); alr.modal({ width: 500, backdrop: 'static' }); } return { alert: _alert, confirm: _confirm } }(); |
四、在需要的地方调用。
1
2
3
4
5
6
7
8
|
Modal.confirm( { msg: "商品已成功加入购物车\n是否去购物车查看?" }) .on( function (e) { if (e) location.href = cart_url; }); |
bootstrap 重写JS的alert、comfirm函数的更多相关文章
- Bootstrap transition.js 插件详解
Bootstrap 自带的 JavaScript 插件的动画效果几乎都是使用 CSS 过渡实现的,而其中的 transition.js 就是为了判断当前使用的浏览器是否支持 CSS 过渡.下面先来简单 ...
- Bootstrap transition.js 插件
Bootstrap transition.js 插件详解 Bootstrap 自带的 JavaScript 插件的动画效果几乎都是使用 CSS 过渡实现的,而其中的 transition.js 就 ...
- Bootstrap的js插件之警告框(alert.js)
data-dismiss="alert"--为关闭button加入该属性能够使其自己主动为警告框赋予关闭功能. .fade .in--为警告框在关闭时加入动画效果. 很多其它细节參 ...
- 修改js confirm alert 提示框文字的简单实例
修改js confirm alert 提示框文字的简单实例: <!DOCTYPE html> <html> <head lang="en"> & ...
- bootstrap插件学习-bootstrap.typehead.js
先看bootstrap.typehead.js的结构 var Typeahead = function ( element, options ){} //构造器 Typeahead.prototype ...
- bootstrap插件学习-bootstrap.dropdown.js
bootstrap插件学习-bootstrap.dropdown.js 先看bootstrap.dropdown.js的结构 var toggle = '[data-toggle="drop ...
- 重写Ext中的typeOf函数
重写Ext中的typeOf函数来解决Ext JS中typeOf对字符串对象.元素节点.文本节点.空白文本节点判断并不准确的问题 重写的typeOf函数使用自己实现的TypeOf函数2中的代码 测试代码 ...
- 使用bootstrap的JS插件实现模态框效果
在上一篇文章中,我们使用 js+css 实现了模态框效果,在理解了模态框的基本实现方法和实现效果后,我们就要寻找更快捷的方法,又快又好的来完成模态框开发需求,从而节约时间,提高效率.一个好的轮子,不仅 ...
- CEF拦截js层alert弹窗 OnJSDialog 《转》
一 引言 CEF3嵌入后,用JS 弹出Alert框,按钮错位,确定按钮勉强能看到.很难看.为了改善体验,决定重写提示框. 环境:VS2008 VC MFC. 二 原理 参看类 CefJSDia ...
随机推荐
- 利用afxDump来调试自己的程序
http://blog.csdn.net/sstower/article/details/7714199
- ie8及其以下浏览器的document.getElementsByClassName兼容性问题
使用JavaScript访问DOM的一个重大问题是,此过程需要一种通过元素类名称来选择类的类函数,对DOMContentReady,这种类函数的缺失导致开发人员需要自己编写自定义脚本业执行上述任务,许 ...
- Jquery实现滚动显示欢迎字幕效果
Jquery控制滚动显示欢迎字幕: 参考代码: <!DOCTYPE html> <html> <head> <title>Colin Marquee W ...
- jquery datagrid加载后仅选定第一行
function onLoadSuccess(data) { var rows = $("#DataGrid").datagrid("getRows"); if ...
- Hadoop之Storm命令
Hadoop之Storm命令 1.storm核心概念 stream--->一列火车 tuple--->一节车厢 数据--->乘客 spout--->始发站 bolt---> ...
- &,引用复制@,忽略错误提示
function &chhua() { static $b="www.jb51.net";//申明一个静态变量 $b=$b."WEB开发"; echo ...
- SVN迁移到Git的过程(+ 一些技巧)
SVN迁移到Git的过程(+ 一些技巧) 李顺利 Key Words SVN,Git,Clone,Conversion,Tips,VCS,Pro Git 关于在VCS中SVN和Git之间的迁移(Clo ...
- vSphere、Hyper-V与XenServer 你选哪个?
vSphere.Hyper-V与XenServer 你选哪个? 当在VMware vSphere.Microsoft Hyper-V与Citrix Systems XenServer之间做出选择时,v ...
- 10. JEB1.5 插件编写二
一些实例 1. 遍历当前光标处函数所有的Element Java代码: import java.io.*; import java.util.List; import jeb.api.IScript; ...
- JavaScript Coding 模式荟萃
1.自运行的匿名函数 <script type="text/javascript" src="./js/jquery-1.7.2.js"></ ...