Blogger Information
Blog 119
fans 3
comment 1
visits 94674
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
layui框架小实战-表单设计
赵大叔
Original
941 people have browsed it

layui框架小实战

1、layui简介

  • layui官网https://www.layui.com/
  • 轻量级前端框架,简单美观。
  • 使用layui:官网下载源码——>导入layui的css样式文件(<link rel="stylesheet" href="layui/css/layui.css">), 导入导入layui的j式文件(<script src="layui/layui.js"></script>)

2、layui表单设计

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>layui</title>
  6. <link rel="stylesheet" href="layui/css/layui.css">
  7. <script src="layui/layui.js"></script>
  8. <style>
  9. header {display: flex;justify-content: space-between;height: 50px;line-height: 50px;
  10. box-sizing: border-box;padding: 0 10px;background-color: black;color: white;font-size: 18px;}
  11. main {display: flex;margin-top: 20px;}
  12. .layui-form-item .layui-input-inline{width: 520px;}
  13. </style>
  14. </head>
  15. <body>
  16. <!--顶部导航-->
  17. <header>
  18. <span>layUI后台管理系统</span>
  19. <div>
  20. <span><i class="layui-icon layui-icon-username"></i></span>
  21. <span>admin</span>
  22. <a href="" style="color: white">退出</a>
  23. </div>
  24. </header>
  25. <main>
  26. <!--left-menu-->
  27. <!--lay-accordion 来开启手风琴,进行折叠操作时,始终只会展现当前的面板。-->
  28. <!--layui-show 展开-->
  29. <div class="layui-collapse" lay-accordion style="width: 200px;">
  30. <div class="layui-colla-item">
  31. <h2 class="layui-colla-title" >从事管理</h2>
  32. <div class="layui-colla-content layui-show">内容区域</div>
  33. </div>
  34. <div class="layui-colla-item">
  35. <h2 class="layui-colla-title">招聘管理</h2>
  36. <div class="layui-colla-content">内容区域</div>
  37. </div>
  38. <div class="layui-colla-item">
  39. <h2 class="layui-colla-title">薪资管理</h2>
  40. <div class="layui-colla-content">内容区域</div>
  41. </div>
  42. </div>
  43. <form class="layui-form" action="">
  44. <div class="layui-form-item">
  45. <label class="layui-form-label">输入框</label>
  46. <div class="layui-input-block">
  47. <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
  48. </div>
  49. </div>
  50. <div class="layui-form-item">
  51. <label class="layui-form-label">密码框</label>
  52. <div class="layui-input-inline">
  53. <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
  54. </div>
  55. <div class="layui-form-mid layui-word-aux">辅助文字</div>
  56. </div>
  57. <div class="layui-form-item">
  58. <label class="layui-form-label">选择框</label>
  59. <div class="layui-input-block">
  60. <select name="city" lay-verify="required">
  61. <option value=""></option>
  62. <option value="0">北京</option>
  63. <option value="1">上海</option>
  64. <option value="2">广州</option>
  65. <option value="3">深圳</option>
  66. <option value="4">杭州</option>
  67. </select>
  68. </div>
  69. </div>
  70. <div class="layui-form-item">
  71. <label class="layui-form-label">复选框</label>
  72. <div class="layui-input-block">
  73. <input type="checkbox" name="like[write]" title="写作" lay-skin="primary">
  74. <input type="checkbox" name="like[read]" title="阅读" checked lay-skin="primary">
  75. <input type="checkbox" name="like[dai]" title="发呆" lay-skin="primary">
  76. </div>
  77. </div>
  78. <div class="layui-form-item">
  79. <label class="layui-form-label">开关</label>
  80. <div class="layui-input-block">
  81. <input type="checkbox" name="yyy" lay-skin="switch" lay-text="ON|OFF" checked>
  82. </div>
  83. </div>
  84. <div class="layui-form-item">
  85. <label class="layui-form-label">单选框</label>
  86. <div class="layui-input-block">
  87. <input type="radio" name="sex" value="男" title="男">
  88. <input type="radio" name="sex" value="女" title="女" checked>
  89. </div>
  90. </div>
  91. <div class="layui-form-item layui-form-text">
  92. <label class="layui-form-label">文本域</label>
  93. <div class="layui-input-block">
  94. <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
  95. </div>
  96. </div>
  97. <div class="layui-form-item">
  98. <div class="layui-input-block">
  99. <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
  100. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  101. </div>
  102. </div>
  103. </form>
  104. </main>
  105. </body>
  106. </html>
  107. <script>
  108. //注意:折叠面板 依赖 element 模块,否则无法进行功能性操作
  109. // left-menu 折叠
  110. layui.use('element', function(){
  111. var element = layui.element;
  112. });
  113. </script>
  114. <script>
  115. //Demo
  116. layui.use('form', function(){
  117. var form = layui.form;
  118. //监听提交
  119. form.on('submit(formDemo)', function(data){
  120. layer.msg(JSON.stringify(data.field));
  121. return false;
  122. });
  123. });
  124. </script>

效果图:

3、总结

1、使用layui很多代码基本粘贴复制,变得很简单。
2、引用老师的话,目前可以先知道怎么用就行,熟悉了再慢慢了解为什么要这么用。

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post