更改默认alert框体
更改框体主要用到的是更改系统的内置控件winpop下面是winpop具体代码
(function(window, jQuery, undefined) {
2
3 var HTMLS = {
4 ovl: '<div class="J_WinpopMask winpop-mask" id="J_WinpopMask"></div>' + '<div class="J_WinpopBox winpop-box" id="J_WinpopBox">' + '<div class="J_WinpopMain winpop-main"></div>' + '<div class="J_WinpopBtns winpop-btns"></div>' + '</div>',
5 alert: '<input type="button" class="J_AltBtn pop-btn alert-button" value="确定">',
6 confirm: '<input type="button" class="J_CfmFalse pop-btn confirm-false" value="取消">' + '<input type="button" class="J_CfmTrue pop-btn confirm-true" value="确定">'
7 }
8
9 function Winpop() {
10 var config = {};
11 this.get = function(n) {
12 return config[n];
13 }
14
15 this.set = function(n, v) {
16 config[n] = v;
17 }
18 this.init();
19 }
20
21 Winpop.prototype = {
22 init: function() {
23 this.createDom();
24 this.bindEvent();
25 },
26 createDom: function() {
27 var body = jQuery("body"),
28 ovl = jQuery("#J_WinpopBox");
29
30 if (ovl.length === 0) {
31 body.append(HTMLS.ovl);
32 }
33
34 this.set("ovl", jQuery("#J_WinpopBox"));
35 this.set("mask", jQuery("#J_WinpopMask"));
36 },
37 bindEvent: function() {
38 var _this = this,
39 ovl = _this.get("ovl"),
40 mask = _this.get("mask");
41 ovl.on("click", ".J_AltBtn", function(e) {
42 _this.hide();
43 });
44 ovl.on("click", ".J_CfmTrue", function(e) {
45 var cb = _this.get("confirmBack");
46 _this.hide();
47 cb && cb(true);
48 });
49 ovl.on("click", ".J_CfmFalse", function(e) {
50 var cb = _this.get("confirmBack");
51 _this.hide();
52 cb && cb(false);
53 });
54 mask.on("click", function(e) {
55 _this.hide();
56 });
57 jQuery(document).on("keyup", function(e) {
58 var kc = e.keyCode,
59 cb = _this.get("confirmBack");;
60 if (kc === 27) {
61 _this.hide();
62 } else if (kc === 13) {
63 _this.hide();
64 if (_this.get("type") === "confirm") {
65 cb && cb(true);
66 }
67 }
68 });
69 },
70 alert: function(str, btnstr) {
71 var str = typeof str === 'string' ? str : str.toString(),
72 ovl = this.get("ovl");
73 this.set("type", "alert");
74 ovl.find(".J_WinpopMain").html(str);
75 if (typeof btnstr == "undefined") {
76 ovl.find(".J_WinpopBtns").html(HTMLS.alert);
77 } else {
78 ovl.find(".J_WinpopBtns").html(btnstr);
79 }
80 this.show();
81 },
82 confirm: function(str, callback) {
83 var str = typeof str === 'string' ? str : str.toString(),
84 ovl = this.get("ovl");
85 this.set("type", "confirm");
86 ovl.find(".J_WinpopMain").html(str);
87 ovl.find(".J_WinpopBtns").html(HTMLS.confirm);
88 this.set("confirmBack", (callback || function() {}));
89 this.show();
90 },
91 show: function() {
92 this.get("ovl").show();
93 this.get("mask").show();
94 },
95 hide: function() {
96 var ovl = this.get("ovl");
97 ovl.find(".J_WinpopMain").html("");
98 ovl.find(".J_WinpopBtns").html("");
99 ovl.hide();
100 this.get("mask").hide();
101 },
102 destory: function() {
103 this.get("ovl").remove();
104 this.get("mask").remove();
105 delete window.alert;
106 delete window.confirm;
107 }
108 };
109
110 var obj = new Winpop();
111 window.alert = function(str) {
112 obj.alert.call(obj, str);
113 };
114 window.confirm = function(str, cb) {
115 obj.confirm.call(obj, str, cb);
116 };
117 })(window, jQuery);
然后实例化对象
1 var obj = new Winpop(); // 创建一个Winpop的实例对象
2 // 覆盖alert控件
3 window.alert = function(str) {
4 obj.alert.call(obj, str);
5 };
6 // 覆盖confirm控件
7 window.confirm = function(str, cb) {
8 obj.confirm.call(obj, str, cb);
9 }; 以下JS不可少
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="winpop.js"></script>
--摘录自他人文章
更改默认alert框体的更多相关文章
- 基于winsocket的框体Server和Client
前面学了一点Winsock的知识,会编写简单的Server和Client,现在就想通过VS2008编写框体的Server和Client,而不是在控制台上的操作了,毕竟学编程就是要多加练习,在实践中发现 ...
- Flutter学习(8)——CheckBox多选框使用及动态更改多选框数据
原文地址:Flutter学习(8)--CheckBox多选框使用及动态更改多选框数据 | Stars-One的杂货小窝 最近项目需求需要调整页面,记录一下实现过程 这次主要是要实现个评价页面,选择不同 ...
- 【小贴士】【stringify神BUG】【localstorage失效】【消灭Safari alert框】【是否延迟加载】【页面10px白屏】
前言 最近碰到几个恶心问题,也发现一点优化技巧,以及对Hybrid知识的一些整理,这里便一并拿出来做分享了,关于Hybrid的调试,会是我今后一个重点 我的博客首先是学习笔记,方便自己做知识沉淀,以后 ...
- webstorm 10 更改默认端口
快捷键 ctrl + Alt + s :打开配置 如图下可以更改 默认端口.快捷键可能跟qq的快捷键冲突,可以关闭qq来设置端口
- Eclipse更改默认工作目录的方法
参考: Eclipse更改默认工作目录的方法:http://blog.163.com/take_make/blog/static/208212210201272611406227/ 用记事本打开&qu ...
- openwrt 更改默认主题
BB 版本默认的主题为 bootstrap,想要修改为其他的主题,可以按照如下方法修改: 1.查看可以使用的主题. "make menuconfig" ---> " ...
- Discuz更改默认搜索模块
由于网站使用DZ的侧重点不同,在搜索中可能需要更改默认搜索模块 首先找到模板中搜索模块对应的文件,默认模板中搜索模块的地址是 template\default\common\pubsearchform ...
- ssh更改默认端口号及实现免密码远程登陆
近来在复习防火墙管理工具 iptables 的基本使用方法,涉及到对端口添加或删除防火墙策略的内容,之前对ssh更改默认端口号及免密码登录的方法不熟悉,这次做一个基本的总结防止自己遗忘. 错误偏差及其 ...
- 如何彻底解决MySQL更改默认字符集以及字符乱码问题!!!
在我们使用MySQL数据库时,字符乱码,对我们来说是一个很头疼的问题.今天笔者就来教大家如何彻底解决更改默认字符集以及字符乱码问题. 当我们使用压缩包进行MySQL安装后,系统会使用默认的字符集,这时 ...
随机推荐
- 一起来玩echarts系列(一)------箱线图的分析与绘制
一.箱线图 Box-plot 箱线图一般被用作显示数据分散情况.具体是计算一组数据的中位数.25%分位数.75%分位数.上边界.下边界,来将数据从大到小排列,直观展示数据整体的分布情况. 大部分正常数 ...
- 背后的故事之 - 快乐的Lambda表达式(一)
快乐的Lambda表达式(二) 自从Lambda随.NET Framework3.5出现在.NET开发者眼前以来,它已经给我们带来了太多的欣喜.它优雅,对开发者更友好,能提高开发效率,天啊!它还有可能 ...
- Socket聊天程序——初始设计
写在前面: 可能是临近期末了,各种课程设计接踵而来,最近在csdn上看到2个一样问答(问题A,问题B),那就是编写一个基于socket的聊天程序,正好最近刚用socket做了一些事,出于兴趣,自己抽了 ...
- java 利用ManagementFactory获取jvm,os的一些信息--转
原文地址:http://blog.csdn.net/dream_broken/article/details/49759043 想了解下某个Java项目的运行时jvm的情况,可以使用一些监控工具,比如 ...
- Javascript正则对象方法与字符串正则方法总结
正则对象 var reg = new Regexp('abc','gi') var reg = /abc/ig 正则方法 test方法(测试某个字符串是否匹配) var str = 'abc123'; ...
- iOS 委托与文本输入(内容根据iOS编程编写)
文本框(UITextField) 本章节继续编辑 JXHypnoNerd .文件地址 . 首先我们继续编辑 JXHypnosisViewController.m 修改 loadView 方法,向 ...
- C#开发微信门户及应用(39)--使用微信JSSDK实现签到的功能
随着微信开逐步开放更多JSSDK的接口,我们可以利用自定义网页的方式来调用更多微信的接口,实现我们更加丰富的界面功能和效果,例如我们可以在页面中调用各种手机的硬件来获取信息,如摄像头拍照,GPS信息. ...
- 微信小程序监控 - HotApp统计
HotApp小程序统计,第一个专业的微信第三方小程序监控统计工具 1.什么是HotApp小程序统计 HotApp小程序统计是第一个微信第三方小程序统计工具,就像做android 和 ios开发的人知道 ...
- 如何区别exists与not exists?
1.exists:sql返回结果集为真:not exists:sql不返回结果集为真.详解过程如图: exists not exists
- IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2 - Unauthorized 由于身份验证头无效,您无权查看此页
因为修改过管理员账号的密码后重启服务器导致IIS无法启动,出现已下异常 1.解决:"启动Windows Process Activation Service时,出现错误13:数据无效&quo ...