最近使用页面弹框,觉得layer.js的弹框功能比较强大而且很好用 以此记录下来
1.layer官网:http://layer.layui.com/ 在这里下载需要的js
2、在引用的前端页面加载layer.js的路径
layer.open({
type: 1, //1代表 content的值例如:'文本';2 代表 content的值例如'../index.html' 就是弹出层直接调用其他地方的页面
// Layer提供了5种层类型。可传入的值有:0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层),
area: ['430px', '260px'],//显示的弹出框的宽度和高度
title:"提示标题",
shade: 0.8,//遮罩层透明度
closeBtn: 1,//0右上角的关闭 x 隐藏掉; 1显示
shadeClose: true,
// scrollbar: false ,//屏蔽浏览器滚动条
// skin: 'layui-layer-rim', //加上边框
content: '<div style="height: 130px; ">conent </div> ',//type=1时
//content: 'xx/xx.jsp' //这里content是一个URL,如果你不想让iframe出现滚动条,你还可以content: ['http://sentsin.com', 'no'] type=2时
btn: ['确定', '取消', '按钮3'] , // 三个按钮的text值
yes: function (index, layero)//或者使用btn1 按钮1的回调
{
layer.close(index);
},
cancel: function (index)//本身自带关闭弹出框功能 对应btn2的回调函数
{
}, btn3: function (index, layero) { //按钮【按钮三】的回调
}});
效果图:
![](https://img-blog.csdnimg.cn/20200317171229785.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMyNzE3NjAz,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20200317173622738.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMyNzE3NjAz,size_16,color_FFFFFF,t_70)
https://blog.csdn.net/a10039/article/details/80494350我觉得这篇写的很不错。