layUI弹框

1.引入jquery和layUI

<script type="text/javascript" src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.layuicdn.com/auto/layui.js" v="layui" e="layui"></script>

2.添加一个按钮或点击事件

<h1 id="open">弹框</h1>

<script>
	$(function() {
		layui.use(['form', 'layer'], function() {
			var form = layui.form,
				layer = layui.layer;

            //id='open'点击事情
			$("#open").click(function() {
				layer.open({
					type: 1,
                    //隐藏的div
					content: $('#divOpen'),
					title: '说明',
					area: ['90%', '90%'],
					fixed: false
						// , resize: false
						// , offset: '5%'
						,
					cancel: function(index, layero) {
						//关闭所有弹出框
						layer.closeAll();
						return true;
					}
				});
			});
		})
	})
</script>

3.添加一个隐藏且即将要显示的div

		<div id="divOpen" style="display: none;height: 100%;">
			<table class="layui-table">
				<thead>
					<tr>
						<th>名称</th>
						<th>描述</th>
					</tr>
				</thead>
				</tbody>
			</table>
		</div>

4.效果

完整版代码

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>弹框</title>
		<script type="text/javascript" src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://www.layuicdn.com/auto/layui.js" v="layui" e="layui"></script>
	</head>

	<body>
		<h1 id="open">弹框</h1>
		<div id="divOpen" style="display: none;height: 100%;">
			<table class="layui-table">
				<thead>
					<tr>
						<th>名称</th>
						<th>描述</th>
					</tr>
				</thead>
				</tbody>
			</table>
		</div>

		<script>
			$(function() {
				layui.use(['form', 'layer'], function() {
					var form = layui.form,
						layer = layui.layer;

					$("#open").click(function() {
						layer.open({
							type: 1,
							content: $('#divOpen'),
							title: '说明',
							area: ['90%', '90%'],
							fixed: false
								// , resize: false
								// , offset: '5%'
								,
							cancel: function(index, layero) {
								//关闭所有弹出框
								layer.closeAll();
								return true;
							}
						});
					});
				})
			})
		</script>
	</body>

</html>

 

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页