弹出框layer的使用封装
layer弹出框官方网址:http://layer.layui.com/
layer常用方法的封装:layerTool.jsp
layer.config({
extend: 'extend/layer.ext.js', //注意,目录是相对layer.js根目录。如果加载多个,则 [a.js, b.js, …]
shift: 0//默认动画风格
});
function Layer(){} ;
Layer.prototype = {
toplayer : window.top.layer , // 获取顶层窗口的layer对象
topWin : window.top , // 获取顶层窗口对象
colseTime : 1000 , // 关闭弹出框的默认时间 1S
width : '800px', // 默认窗口的宽度
height : '600px', // 默认窗口的高度
px : 'px' , // 对话框宽高单位
/**
* 警告框
* @param {} content 警示的内容
*/
showAlert : function(content){
this.toplayer.alert(content,{icon:0});
},
/**
* 操作成功提示框
* @param {} content 提示内容 默认:操作成功
* @param {} callback 回调方法
*/
showSucAlert : function (content,callback){
var length = arguments.length ; // 实际传入参数的长度
var options = {icon:1,time:this.colseTime};
if(length == 0){ // 没有传入任何参数
this.toplayer.alert("操作成功",options);
}else if(length == 1){ // 传入了提示内容
this.toplayer.alert(content,options);
}else if(length == 2){ // 有回调函数的,将不自动关闭
this.toplayer.alert(content,{icon:1},callback);
}
},
/**
* 操作失败提示框
* @param {} content 提示内容 默认:操作失败
* @param {} time 关闭时间(单位毫秒) 默认:1S,0:表示不自动关闭
*/
showFailAlert : function(content,time){
var length = arguments.length ; // 实际传入参数的长度
var options = {icon:2,time:this.colseTime};
if(length == 0){ // 没有传入任何参数
this.toplayer.alert("操作失败",options);
}else if(length == 1){ // 传入了提示内容
this.toplayer.alert(content,options);
}else if(length == 2){ // 传入了关闭时间
options.time = time ;
this.toplayer.alert(content,options);
}
},
/**
* 打开一个对话框(没有回调函数)
* @param {} title 对话框标题(必须)
* @param {} url 对话框URL(必须)
* @param {} width 对话框宽度 默认:800px
* @param {} height 对话框高低 默认:600px
*/
openDialogNoCallBack : function(title,url,width,height){
this.toplayer.open({
type : 2,
title : title ,
content : url ,
maxmin: true,
area: [width, height]
});
},
/**
* 获取当前的窗口对象
* @return {}
*/
getCurrentWin : function(){
return this.topWin.frames['ifr_center'] ;
},
/**
* 打开一个对话框(带回调函数)
* @param {} title 对话框标题(必须)
* @param {} url 对话框URL(必须)
* @param {} width 对话框宽度 默认:800px
* @param {} height 对话框高低 默认:600px
*/
openDialogWithCallBack : function(title,url,width,height,callback){
this.toplayer.open({
type : 2,
title : title ,
content : url ,
area: [width, height],
maxmin: true,
end : callback
});
},
/**
* 打开一个对话框(没有回调函数)
* @param {} title 对话框标题(必须)
* @param {} url 对话框URL(必须)
* @param {} width 对话框宽度 默认:800px
* @param {} height 对话框高低 默认:600px
* @param {} callback 窗口销毁时的回调方法
*/
openDialog : function(title,url,width,height,callback){
var length = arguments.length ; // 实际传入参数的长度
if(length == 2){ // 默认宽高
this.openDialogNoCallBack(title,url,this.width,this.height)
}else if(length == 3){ // 只传入宽度参数
width += this.px ;
this.openDialogNoCallBack(title,url,width,this.height)
}else if(length == 4){ // 传入宽度和高度
width += this.px ;
height += this.px ;
this.openDialogNoCallBack(title,url,width,height)
}else if(length == 5){ // 带回调函数
width += this.px ;
height += this.px ;
this.openDialogWithCallBack(title,url,width,height,callback);
}
},
/**
* 关闭弹出层
* @param {} index
*/
closeLayer : function(index){
this.toplayer.close(index);
},
/**
* 关闭所有的Dialog
*/
closeDialog : function(){
this.toplayer.closeAll('iframe');
},
/**
* 关闭Dialog带有操作成功的提示
* @param {} content
*/
closeDialogWithMsg : function(content){
this.toplayer.closeAll('iframe');
if(!content) content = "操作成功" ;
this.showSucMsg(content);
},
/**
* 显示提示框
* @param {} content
*/
showMsg : function(content){
this.toplayer.msg(content,{time:this.colseTime}) ;
},
/**
* 显示操作成功的提示框
* @param {} content
*/
showSucMsg : function(content){
if(!content) content = "操作成功" ;
this.toplayer.msg(content,{icon: 1,time:this.colseTime}) ;
},
/**
* 显示验证框
* @param {} content 提示内容
* @param {} yesFunction 确定以后的回调函数
*/
showConfirm : function(content,yesFunction){
this.toplayer.confirm(content,{
btn: ['确定', '取消'],
icon : 3
},yesFunction);
}
};
var Layer = new Layer();
<!--Demo--> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LayerDemo演示</title>
<script type="text/javascript" src="/ydzf/scripts/plugin/jquery/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="/ydzf/scripts/plugin/layer/layer.js"></script>
<script type="text/javascript" src="/ydzf/scripts/plugin/layer/layerTool.js"></script>
</head>
<body>
<h2>LayerDemo演示</h2>
Alter
<button onclick="Layer.showAlert('有问题了啊');">alert</button>
<button onclick="Layer.showSucAlert();">操作成功提示框</button>
<button onclick="Layer.showSucAlert('我成功了',showCall);">操作成功提示框+自定义提示内容+回调方法</button> <button onclick="Layer.showFailAlert();">操作失败提示框</button>
<button onclick="Layer.showFailAlert('我失败了',0);">操作失败提示框+自定义提示内容+不自动关闭</button>
<br/>
OpenDialog
<button onclick="Layer.openDialog('我是Open窗口','demo02Edit.jsp');">对话框</button>
<button onclick="Layer.openDialog('我是Open窗口','demo02Edit.jsp',400);">对话框+自定义宽</button>
<button onclick="Layer.openDialog('我是Open窗口','demo02Edit.jsp',500,500);">对话框+自定义宽高</button>
<br/>
Message
<button onclick="Layer.showMsg('我只是简单的提示一下');">对话框</button>
<button onclick="Layer.showSucMsg('我是成功的提示框')">成功的提示框</button>
<br/>
Confirm
<button onclick="Layer.showConfirm('你确定要这样操作吗',function(index){alert('是的')});">Confirm对话框</button>
<script type="text/javascript">
function showCall(index){
alert("我是回调奥"+index);
Layer.closeLayer(index);
}
</script>
</body>
</html>
弹出框layer的使用封装的更多相关文章
- JS弹出框插件zDialog再次封装
zDialog插件网址:http://www.jq22.com/jquery-info2426 再次封装zDialog的代码: (function ($) { $.extend({ iDialog: ...
- 弹出框layer插件
有时候我们在网页制作中需要引用各种弹出框,弹出框的展现形式多种多样.可以是弹出图片,视频,文字,也可以是弹出图片轮播等形式: 弹出框插件——layer使用方法(其实官方文档中已经介绍的很详细): 下载 ...
- Layui 好用的弹出框
layui的下载地址: http://www.layui.com/ 需要引用layui里面的css跟js layui自带jquery var $ = layui.$ 一个直接弹出另一个窗体的弹出框 w ...
- vue之element-ui设置全局弹出框
这样的需求,在主要功能完成后,需要进行交互效果的完善,需要给请求api的时候添加一个加载中的一个弹出框.但是每个页面每个页面过的话,会很费时间和精力,这里我们可以采用element-ui中的服务式弹出 ...
- 关于Layer弹出框初探
layer至今仍作为layui的代表作,她的受众广泛并非偶然,而是这五年多的坚持,不断完善和维护.不断建设和提升社区服务,使得猿们纷纷自发传播,乃至于成为今天的Layui最强劲的源动力.目前,laye ...
- layer弹出框小结
1.layer.open() // 1.打开弹出层 layer.open({ type:1, //基本层类型 icon:, //图标 content:'请核对信息!', //内容 shade:0.3, ...
- Android 学习笔记之AndBase框架学习(二) 使用封装好的进度框,Toast框,弹出框,确认框...
PS:渐渐明白,在实验室呆三年都不如在企业呆一年... 学习内容: 1.使用AbActivity内部封装的方法实现进度框,Toast框,弹出框,确认框... AndBase中AbActivity封 ...
- 使用layer显示弹出框笔记
$.layer({ area : ['200px','auto'], //控制层宽高.当设置为auto时,意味着采用自适应, 当然,对于宽度,并不推荐这样做.例如:area : ['310px ...
- 原生Js封装的弹出框-弹出窗口-页面居中-多状态可选
原生Js封装的弹出框-弹出窗口-页面居中-多状态可选 实现了一下功能: 1.title可自定义 可拖拽 2.width height可以自定义 3.背景遮罩和透明度可以自定义 4.可以自己编辑弹出 ...
随机推荐
- 成都传智播客java就业班和基础班
传智播客成都Java培训,带你走进Java的世界... 我们有咨询的教育团队,一流的名师指导: 我们是重视基础理论建设,强化高端应用技能: 我们有四大JavaEE项目,海量Android项目: 我们是 ...
- (step4.3.1) hdu 1010(Tempter of the Bone——DFS)
题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...
- Linux下基于源代码方式安装MySQL 5.6
MySQL为开源数据库,因此能够基于源代码实现安装.基于源代码安装有很多其它的灵活性. 也就是说我们能够针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码.依据不同的软件平台环境调整相关的编译 ...
- openwrt sdk compile
recently ,bought a router : tl-wr741n-v5 hd my aim : let the router dail in neetkeeper environment : ...
- C#基础语法总结
C#笔记——基础篇 一.入门知识 VS中的常用快捷键 Ctrl+K+D:快速对齐代码 Ctrl+Z:撤销 Ctrl+S:保存(一定要经常保存!) Ctrl+J:快速弹出智能提示 Shift+End . ...
- 初学Java ssh之Spring 第一篇
之前虽然毕业前实习的工作是使用的C# .NET语言,但是,毕业后还是果断应聘Java.虽然自己对Java的理解不如C#深入,只是对基础知识比较熟悉,但还是义无返顾了··· 虽然应聘经历比较坎坷,但最终 ...
- ORA-02447: cannot defer a constraint that is not deferrable
一个constraint如果被定义成deferrable那么这个constraints可以在deferred和imediate两种状态相互转换. deferred只在transaction中有效,也就 ...
- OC基础 文件管理
OC基础 文件管理 1.文件管理类NSFileManager对象的创建: NSFileManager *fm = [NSFileManager defaultManager]; 2.文件操作: (1 ...
- 报错: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is ins
环境:Xcode7.1.1 + iOS9.1 详细错误: App Transport Security has blocked a cleartext HTTP (http://) resource ...
- struts2 JS获取上传文件的绝对路径,兼容IE和FF
因为file控件上传失败后会自动清空,所以使用文本框来保存上传路径,而且在不同的浏览器下,控件的样式也需要兼容.下面是自己用到的实例 // 初始化判断浏览器的版本,根据版本的不同使用不同的样式func ...