更改默认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>

--摘录自他人文章
时间: 2024-08-02 20:54:04

更改默认alert框体的相关文章

基于winsocket的框体Server和Client

前面学了一点Winsock的知识,会编写简单的Server和Client,现在就想通过VS2008编写框体的Server和Client,而不是在控制台上的操作了,毕竟学编程就是要多加练习,在实践中发现不懂的地方,然后解决,然后再发现…… 当然,作为一个刚接触Winsock的新手,大部分知识都来自于网上的资料,包括接下来的代码也是借鉴... 第一步利用VS2008创建一个Windows窗体应用程序chatServer(过程略): 设计你的窗体,简单的设计了一个窗体注意,每一个组件都需要有唯一的Na

更改默认添加到活动目录的客户端数量

我们启用"将工作站添加到域"策略以后,只允许普通用户添加10个计算机账户,超过十个以后此用户账户就不能再将计算机加入域,工作需要,管理员可以修改这个值.请看下面讲述. (由于环境是英文的,请大家对照相应的中文去找,还请大家谅解.如有问题请给我博客留言,谢谢!) "运行"中输入"adsiedit.msc"打开ADSI编辑器,连接到"DC=contoso,DC=com"(默认) 右击DC=contoso,DC=COM,选择&quo

ahjesus linux连接阿里云ubuntu服务器并更改默认账号和密码,以及创建子账户

先确保本地Linux服务器SSH服务开启,如果没有开启直接执行指令:service sshd start 然后我们使用ssh指令进行远程登陆 ssh [email protected] 输入passwd指令修改旧密码 修改默认账号root vi /etc/passwd 按i键进入编辑状态 修改第1行第1个root为新的用户名 按esc键退出编辑状态,并输入:x保存并退出 vi /etc/shadow 按i键进入编辑状态 修改第1行第1个root为新的用户名 按esc键退出编辑状态,并输入:x!强

centos7 centos6中 更改默认的系统启动级别

centos6中更改默认的启动级别 方法: 1.vi /etc/inittab 2.找到id:x:initdefault:,我的系统是id:3:initdefault:,即默认以字符模式启动. 3.将3改为5即可,即id:5:initdefault: 4.reboot liunx中6个默认的启动级别, 0 关机 1 单用户模式 2 不带网络的多用户模式 3 带网络的多用户,也就是所谓的纯字符模式 4 保留,用户可以自给定义 5 图形界面的多用户模式 6 重起系统 centos7 与centos6

ALSA 更改默认声卡

用 aplay -l 看一下各声卡的配置信息 创建 /etc/asound.conf,根据 aplay -l  的输入,选择需要的声卡信息,按如下格式添入,即可更改默认声卡 defaults.pcm.card 1 defaults.pcm.device 1 defaults.ctl.card 1

dataTables去掉搜索框和每页多少条框体,解决Cannot reinitialise DataTable问题

$('#example').DataTable({ searching:false, //去掉搜索框 bLengthChange:false,//去掉每页多少条框体 "language": { "info": "", // 表格左下角显示的文字 "paginate": { "previous": "上一页", "next": "下一页" } },

如何在PeopleSoft中找到并更改默认样式表名称

PeopleSoft的默认样式表名称是用来控制应用程序的外观的.在PeopleSoft中可以使用集中样式表来更改应用程序的外观,oracle为每个应用程序版本设置了默认的样式表. 下面是不同应用程序版本对应的默认样式表. 9.0或更早版本~PSSTYLEDEF 9.1~PSSTYLEDEF_SWAN 9.2~PSSTYLEDEF_TANGERINE 查找当前版本使用的默认样式表 1.路径:主菜单>PeopleTools>实用程序>管理>PeopleTools选项 找到默认样式表名称

webstorm 10 更改默认端口

快捷键 ctrl + Alt + s :打开配置 如图下可以更改 默认端口.快捷键可能跟qq的快捷键冲突,可以关闭qq来设置端口

laravel更改默认的登录密码加密方式

laravel 默认用的登录密码加密方式是: $password = Hash::make('password'); 而我平时用的密码加密方式是: $password = md5('password'.'salt'); //其中的salt是一个随机串 那么怎么把默认的改成自己想要的呢? 我谷歌了一下,还真让我找到了.转送:http://blueve.me/archives/898 为了防止这个网站打不开,我自己再稍微整理了一下,以备后用: 首先,打开这个文件夹:/vender/laravel/f