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 ...
随机推荐
- editplus如何配置php编译环境?
为什么要配置php编译? 因为,要先看看 php文件是否能够 编译得过去, 有没有错误, 如果有错误, 不能通过编译, 则肯定不能运行. 所以, 可以先看一下编译 得不得行. 在preferences ...
- dubbo框架----初探索-配置
使用框架版本 dubbo-2.5.3 spring-4.2.1.RELEASE jdk-1.8 tomcat-8.0 zookeeper-3.3.6 Dubbo与Zookeeper.SpringMVC ...
- 繁华模拟赛day8 字典序
/* 这个题要我们求一个字典序,字符串给出的顺序,会对字母的字典序前后相对顺序进行限定,如何用来表示这种限定,我们注意到这种一个之后接着一个,只有先输出他前面的才能输出他,很明显就是拓扑排序,最小方案 ...
- ACM_1 大数求和
/*1 *2014.11.18 *大数求和 */ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <strin ...
- 数论只会GCD。。。
一些关于GCD的代码.... #include <iostream> #include <cstdio> #include <cstring> using name ...
- HomeWork2
程序一: 1 public intfindLast(int[] x, inty) { 2 //Effects: If x==null throw NullPointerException 3 // e ...
- javascript高级程序设计---DOM
DOM是文档对象模型的简称,DOM的基本思想是把结构化文档解析成一系列的节点,由这些节点组成数装的DOM树,所有的这些节点和最终的树状结构都有统一的对外接口,达到使用编程语言操作文档的目的,DOM可以 ...
- CSS3圆角边框的使用-遁地龙卷风
0.快速入门 border-radius:50px; 1.border-radius详解 border-radius:50px; 上右下左,水平和垂直距离都是50px border-radius:50 ...
- BZOJ1251——序列终结者
给你一个数列,让你实现区间加上一个值,区间翻转,区间最大值 裸splay,懒标记一发即可 #include <cstdio> #include <cstdlib> #inclu ...
- Xcode 中的黄色文件夹/蓝色文件夹
蓝色.黄色首先是和你导入文件夹时的勾选项目有关系: 黄色:-->group 蓝色:--> folder 在group中的.m/.h文件,#import "xxxxx.h" ...