代码:
1、index.html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="layui/css/layui.css" />
<script src="layui/layui.js"></script>
<title>Layui的使用</title>
<style>
.nav {
height: 50px;
background-color: #484848;
color: white;
font-size: 1.2rem;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
}
.nav a {
color: whitesmoke;
}
.nav a:hover {
color: darkgray;
}
.nav > div:last-child {
width: 160px;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.container {
display: flex;
}
.container > .menu {
width: 200px;
}
.container > .iframe {
flex-grow: 1;
height: 670px;
}
.container > .iframe > iframe {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<!-- 头部导航 -->
<div class="nav">
<div>
<span>CMS后台管理</span>
</div>
<div>
<i class="layui-icon layui-icon-username" style="font-size: 1.2em;"></i>
<a href="">admin</a>
<a href="">退出</a>
</div>
</div>
<!-- 主体部分 -->
<div class="container">
<div class="menu">
<div class="layui-collapse" lay-accordion>
<div class="layui-colla-item">
<h2 class="layui-colla-title">管理</h2>
<div class="layui-colla-content layui-show">
<a href="from.html" target="user">用户</a>
</div>
</div>
<div class="layui-colla-item">
<h2 class="layui-colla-title">商品</h2>
<div class="layui-colla-content">大成168</div>
</div>
<div class="layui-colla-item">
<h2 class="layui-colla-title">文章</h2>
<div class="layui-colla-content">文章系统上线啦!</div>
</div>
</div>
</div>
<div class="iframe">
<iframe
src="test.html"
frameborder="0"
scrolling="no"
name="user"
placeholder="欢迎来到CMS管理系统"
>
</iframe>
</div>
</div>
</body>
<script>
//注意:折叠面板 依赖 element 模块,否则无法进行功能性操作
layui.use("element", function () {
var element = layui.element;
//…
});
</script>
</html>
2、form.html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="layui/css/layui.css" />
<script src="layui/layui.js"></script>
<title>Document</title>
<style>
body {
height: 1200px;
background-color: lightgreen;
}
form {
padding: 10px;
font-size: 1.2em;
}
.layui-input-block {
width: 360px;
}
.layui-form-label {
text-align: center;
}
</style>
</head>
<body>
<form action="" class="layui-form">
<div class="layui-form-item">
<label for="" class="layui-form-label">用户名:</label>
<div class="layui-input-block">
<input
type="email"
placeholder="email@163.com"
class="layui-input"
required
lay-verify="required"
/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密 码:</label>
<div class="layui-input-inline">
<input
type="password"
name="title"
required
lay-verify="required"
placeholder="*********"
autocomplete="off"
class="layui-input"
/>
</div>
<div class="layui-form-mid layui-word-aux">密码不少于6位</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">选择框:</label>
<div class="layui-input-block">
<select name="area" id="">
<option value="1">华东</option>
<option value="2" checked>华北</option>
<option value="3" disabled>华中</option>
<optgroup label="东北地区">
<option value="01">黑龙江</option>
<option value="02">吉林</option>
<option value="03">大连</option>
</optgroup>
</select>
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">爱好:</label>
<div class="layui-input-block">
<input type="checkbox" title="写作" name="model[]" />
<input type="checkbox" title="阅读" name="model[]" checked />
<input
type="checkbox"
title="阅读"
name="model[]"
lay-skin="switch"
lay-text="ON|OFF"
checked
/>
<input
type="checkbox"
title="单词"
name="modol[]"
lay-skin="primary"
/>
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">性别:</label>
<div class="layui-input-block">
<input type="radio" title="男" name="sex" checked />
<input type="radio" title="女" name="sex" />
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">个人介绍</label>
<div class="layui-input-block">
<textarea
name=""
id=""
cols="30"
rows="10"
placeholder="输入不少于100字的个人介绍"
class="layui-textarea"
style="resize: none;"
></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn">提交</button>
<button type="reset" class="layui-btn layui-btn-warm">重置</button>
</div>
</div>
</form>
</body>
<script>
//Demo
layui.use("form", function () {
var form = layui.form;
//监听提交
form.on("submit(formDemo)", function (data) {
layer.msg(JSON.stringify(data.field));
return false;
});
});
</script>
</html>
3、test.html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
background-color: #00ffff;
display: flex;
justify-content: center;
justify-items: center;
align-items: center;
align-content: center;
}
div > h1 {
color: lightblue;
}
</style>
</head>
<body>
<div><h1>欢迎来CMS管理系统</h1></div>
</body>
</html>