给Jquery添加alert,prompt方法,类似系统的Alert,Prompt,可以响应键盘,支持拖动
我们在调用系统的Alert,prompt的弹出提示时,不同的系统会有不同的提示框,视觉效果不统一,而且不好看,功能单一,现在我们通过Jquery模拟Alert,prompt,现实统一视觉效果,而且内容丰富的弹出提示。
Jquery可以扩展自己的功能,如果对Jquery开发插件不熟悉的人可以到官方网去看看文档,比较简单易懂。
- /*
- * 本插件基于JQUERY
- * Jquery版本: 1.7.2
- * Date:2012-06-28
- * Author:Kingwell
- * E-mail:jinhua.leng##gmail.com
- *
- * ---------- 接口说明: ----------
- *
- * --本插件采用kw命名空间,给Jquery添加静态方法,故调用方法为 $.kw.方法名 参数如下:
- * --调用方法:
- * --alert $.kw.alert(content,title,callBack)
- * --prompt $.kw.prompt(title,content,callBack)
- *
- *
- * -- title 标题名称 如果缺省,则为默认标题,如:"系统提示"
- * -- content 内容显示的内容
- * --callback 回调函数,单击确定后要执行的内容
- *
- *
- * --功能:类似系统功能,支持拖动,响应键盘事件,ESC退出,Enter确定,以及回调函数功能。
- *
- *
- */
- $(function () {
- $.kw = {
- title : "System information", //默认标题 可修改
- speed : 400, //默认速度 可修改
- buttonName : "OK", //确定按钮默认名称 可修改
- cancel : "Cancel", //取消按钮默认名称 可修改
- content : "Content",
- //移除遮盖层
- del : function () {
- $("#alert-layer").remove();
- },
- //响应ESC键盘退出
- esc : function () {
- $(document).keyup(function (event) {
- if (event.which == 27) {
- $.kw.del();
- }
- });
- },
- //内容显示功能
- alert : function (sContent, sTitle, callBack) {
- var title = sTitle || this.title;
- var layer = "<div id='alert-layer'><div id='alert-container'><div class='alert-top'></div><div class='alert-box'><div id='alert-title'>" + title + "<div id='alert-close' title='Close'></div></div><div id='alert-content'>" + sContent + "</div><div class='alert-button'><button id='alert-button'>" + this.buttonName + "</button></div></div><div class='alert-bottom'></div></div></div>";
- $(layer).fadeIn(this.speed).appendTo("body");
- this.setting();
- this.move();
- $("#alert-button").focus();
- $("#alert-close").bind("click", this.del); //移除层
- $("#alert-button").bind("click", function () {
- if (callBack) {
- callBack();
- }
- $.kw.del();
- }); //移除层
- this.esc();
- },
- //提示
- confirm : function (sContent, callBack, sTitle) {
- var title = sTitle || this.title;
- var content = sContent || this.content;
- var layer = "<div id='alert-layer'><div id='alert-container'><div class='alert-top'></div><div class='alert-box'><div id='alert-title'>" + title + "<div id='alert-close' title='Close'></div></div><div id='alert-content'>" + sContent + "</div><div class='alert-button'><button id='alert-button'>" + this.buttonName + "</button><button id='alert-cancel'>" + this.cancel + "</button></div></div><div class='alert-bottom'></div></div></div>";
- $(layer).fadeIn(this.speed).appendTo("body");
- this.setting();
- $("#alert-button").focus(); //获得焦点
- this.move(); //拖动
- $("#alert-close").bind("click", this.del); //移除层
- $("#alert-cancel").bind("click", this.del); //移除层
- $("#alert-button").bind("click", function () {
- $.kw.del();
- if (callBack) {
- callBack();
- };
- }); //移除层
- this.esc();
- },
- //框拖动功能
- move : function () {
- $("#alert-title").mousedown(function (event) {
- var l = parseInt($("#alert-container").css("left")),
- t = parseInt($("#alert-container").css("top"));
- x = event.pageX - l;
- y = event.pageY - t;
- $("body").bind("mousemove", function (event) {
- $("#alert-container").css({
- "left" : (event.pageX - x)
- });
- $("#alert-container").css({
- "top" : (event.pageY - y)
- });
- //$("#alert-container").fadeTo(0,0.9)
- });
- });
- $("body").mouseup(function () {
- $("body").unbind("mousemove");
- //$("#alert-container").fadeTo(0,1)
- });
- },
- //设置背景层与内位置
- setting : function () {
- var bcw = document.documentElement.clientWidth,
- bch = document.documentElement.clientHeight,
- bsh = document.documentElement.scrollHeight,
- aw = $("#alert-container").width() / 2,
- ah = $("#alert-container").height() / 2;
- $("#alert-layer").css("height", bsh);
- $("#alert-container").css({
- "top" : bch / 2 - ah,
- "left" : bcw / 2 - aw
- });
- }
- //$.kw End
- };
- });
- #alert-layer button:focus{border:1px solid #AAA!important; background:#789!important; color:white; outline:none}
- #alert-layer{position:absolute;left:0;top:0;width:100%;height:100%;color:#333;line-height:1;z-index:10000; background:rgba(0,0,0,0.1)}
- #alert-layer #alert-container{border-radius:3px; padding:10px; width:390px; position:fixed; _position:absolute;}
- #alert-layer .alert-top{background:url(images/conner2.png) no-repeat left top; height:10px;}
- #alert-layer .alert-bottom{background:url(images/conner2.png) no-repeat left bottom; height:10px;}
- #alert-layer #alert-title{font-size:15px; height:30px;line-height:25px;padding:0 10px;position:relative;font-weight:bold;cursor:move;}
- #alert-layer #alert-close{background: url(images/close.gif) no-repeat center center; width:25px; height:25px; position:absolute; cursor:pointer; right:2px; top:0px;}
- #alert-layer .alert-button{ padding:5px 10px; text-align:right}
- #alert-layer #alert-content{background:#F1F1F1; border-top:1px solid #B9B9B9; border-bottom:1px solid #B9B9B9; padding:10px 15px;}
- .alert-box{background:url(images/tc_bg.png) repeat-y left top; padding:0 6px}
- #alert-layer button{padding:5px; border:1px solid #CCC; margin:auto 5px; border-radius:2px; min-width:60px;}
- #alert-layer h1,#alert-layer h2,#alert-layer h3,#alert-layer h4{margin:10px auto; font-size:16px}
调用方法:
- $.kw.alert("提示内容")
- $.kw.alert("提示内容","系统提示")//修改弹出框提示标题
- $.kw.comport("提示内容");
给Jquery添加alert,prompt方法,类似系统的Alert,Prompt,可以响应键盘,支持拖动的更多相关文章
- jquery添加属性的方法
$("#id" ).prop('checked', true); $("#id" ).attr('checked', 'true');
- jQuery自定义alert,confirm方法及样式
学过JavaScript的都知道,alert().confirm()都是window对象特有的方法,而这两个方法我们平时使用的频率也很高,但是比较扎心的就是他自带的样式太... 因此,我整理了一个比较 ...
- 如何为jquery添加方法
以下内容引自一位网友的帖子: jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法.jQuery的全局函数就是属于jQuery ...
- element弹框的的this.$alert、this.$prompt方法用法
调用$alert方法即可打开消息提示,它模拟了系统的 alert,无法通过按下 ESC 或点击框外关闭 调用$prompt方法即可打开消息提示,它模拟了系统的 prompt
- 为jQuery添加Webkit的触摸方法支持
前些日子收到邮件,之前兼职的一个项目被转给了其他人,跟进的人来问我相关代码的版权问题. 我就呵呵了. 这段代码是我在做13年一份兼职的时候无聊加上去的,为jQuery添加触摸事件的支持.因为做得有点无 ...
- jquery 添加节点的几种方法介绍
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 原生JS添加节点方法与jQuery添加节点方法的比较及总结
一.首先构建一个简单布局,来供下边讲解使用 1.HTML部分代码: <div id="div1">div1</div> <div id="d ...
- JS添加节点方法与JQuery添加节点方法的比较及总结
原生JS添加节点方法与JQuery添加节点方法的比较及总结 一.首先构建一个简单布局,来供下边讲解使用 1.HTML部分代码: <div id="div1">div ...
- 通示jQuery实例方法,未DOM对象添加多个方法
<script type="text/javascript"> /* * 通示jQuery实例方法,未DOM对象添加多个方法 * 用按钮做多个事件的调用 */ (fun ...
随机推荐
- Express中使用mongodb存储session
express默认有队session的支持,但是是存储在内存中的. 我们可以使用mongodb来存储会话. 但是express的各个版本中对该功能的写法是不同的. Express 2.x: app.u ...
- (转)如何构建高性能,稳定SOA应用之-负载均衡-Decoupled Invocation(一)
当我们在为一个软件设计架构的时候,我们不仅仅要确保所做出来的架构要满足系统的业务需求,更加要确保做出来的架构要满足可维护性,安全,稳定性的非业务行的需求. 另外一个非常重要的非功能性需求就是性能.性能 ...
- http: URL、请求方式
URL:统一资源定位符,可以从互联网得到和访问资源,是标准资源的位置 结构包括协议.服务器名称(IP地址).端口(有的服务器需要).路径.文件名 协议:告诉浏览器如何处理打开的文件,常用的就是http ...
- flume+kafka (分区实现 默认单分区)
这篇文章主要是log4j+flume+kafka的内容 首先从从下面的地址下载flume+kafka的插件包 https://github.com/beyondj2ee/flumeng-kafka-p ...
- Linux 静态库和动态库 使用说明
Linux下程序运行中,有两种库,静态库和动态库. 静态库:名字一般为libxxx.a,编译时会整合到可执行程序中,优点是运行时不需要外部函数库支持,缺点是编译后程序较大,一旦静态库改 ...
- C++ 中的 const 详解
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4235721.html 1.为什么使用 const int 而不使用 #define 在使用# ...
- ROS
1 SSH 为什么我用 ssh 用户名 就不行,用 ssh xxx.xxx.xxx.xxx -l 用户名 就可以了呢 2 SCP 传送文件到另一个IP 用法: scp xxx root@xx.x ...
- 【转】HttpServletRequest.getParameter() &HttpServletRequest.getAttribute() 区别
Ref: HttpServletRequest的getParameter和getAttribute方法有什么区别 具体如下几点: (1)HttpServletRequest类有setAttribute ...
- mongodb持久化
先上一张图(根据此处重画),看完下面的内容应该可以理解. mongodb使用内存映射的方式来访问和修改数据库文件,内存由操作系统来管理.开启journal的情况,数据文件映射到内存2个view:pri ...
- JQ 选择器大全
一.基本选择器 选择器 描 述 返回 示例 #id 根据给定id匹配一个元素 单个元素 $("#test") 选取id为test的元素 .class 根据给定类名匹配一个元素 集合 ...