博客列表 >layui基础知识

layui基础知识

Jason
Jason原创
2020年06月02日 16:18:09903浏览

作业地址

作业地址 : layui基础知识

做作业的过程中,有几个容易犯错的点记录一下.

  • lay-filter是写在标签里面的,不是写在容器上

放上源码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>注册页面</title>
  6. <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
  7. <script type="text/javascript" src="layui/layui.js"></script>
  8. <style type="text/css" media="screen">
  9. .layui-form-label {
  10. /*width:300px;*/
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div class="layui-form">
  16. <div class="layui-form-item">
  17. <label class="layui-form-label">输入框</label>
  18. <div class="layui-input-inline">
  19. <input type="text" name="" class="layui-input" placeholder="请输入标题">
  20. </div>
  21. </div>
  22. <div class="layui-form-item">
  23. <label class="layui-form-label">请输入大名</label>
  24. <div class="layui-input-inline">
  25. <input type="text" name="" class="layui-input" placeholder="请输入标题">
  26. </div>
  27. <div class="layui-form-mid layui-word-aux">张三李四王五</div>
  28. </div>
  29. <div class="layui-form-item">
  30. <label class="layui-form-label">选择框</label>
  31. <div class="layui-input-inline">
  32. <select name="city" lay-filter="test">
  33. <option value=""></option>
  34. <option value="0">北京</option>
  35. <option value="1">上海</option>
  36. <option value="2">广州</option>
  37. <option value="3">深圳</option>
  38. <option value="4">杭州</option>
  39. </select>
  40. </div>
  41. <div name="city" class="layui-input-inline">
  42. </div>
  43. </div>
  44. <div class="layui-form-item">
  45. <label class="layui-form-label">复选框</label>
  46. <div class="layui-input-block">
  47. <input type="checkbox" name="" title="写作" checked>
  48. <input type="checkbox" name="" title="睡觉">
  49. <input type="checkbox" name="" title="禁用" disabled>
  50. <input type="checkbox" name="" title="小的" lay-skin="primary">
  51. <input type="checkbox" name="" title="女朋友" lay-skin="primary">
  52. </div>
  53. </div>
  54. <div class="layui-form-item">
  55. <label class="layui-form-label">状态</label>
  56. <div class="layui-input-block" >
  57. <input type="checkbox" name="xxx" lay-skin="switch" lay-text="开启|关闭" lay-filter="test">
  58. </div>
  59. </div>
  60. <div class="layui-form-item">
  61. <label class="layui-form-label">性别</label>
  62. <div class="layui-input-block">
  63. <input type="radio" name="sex" value="1" title="男">
  64. <input type="radio" name="sex" value="2" title="女">
  65. <input type="radio" name="sex" value="3" title="保密">
  66. </div>
  67. </div>
  68. <div class="layui-form-item">
  69. <label class="layui-form-label">性别</label>
  70. <div class="layui-input-inline">
  71. <textarea name="" class="layui-textarea"></textarea>
  72. </div>
  73. </div>
  74. <div class="layui-form-item">
  75. <div class="layui-input-block">
  76. <button class="layui-btn">提交</button>
  77. <button class="layui-btn layui-btn-primary">重置</button>
  78. </div>
  79. </div>
  80. </div>
  81. </body>
  82. </html>
  83. <script>
  84. layui.use('form', function(){
  85. var form = layui.form;
  86. $ = layui.jquery;
  87. form.on('select(test)', function(data){
  88. console.log(data.value);
  89. if(data.value >= 0) {
  90. var citys = ['长沙','衡阳'];
  91. var html = '<select>';
  92. $.each(citys,function(i, v) {
  93. html += ('<option>' + v + '</option>');
  94. });
  95. html += '</select>';
  96. $('div[name="city"]').html(html);
  97. form.render;
  98. }
  99. });
  100. // switch
  101. form.on('switch(test)', function(data){
  102. console.log(data.elem.checked);
  103. layer.confirm('是否要开启?', {
  104. btn: ['开启','不开启'] //按钮
  105. }, function(){
  106. layer.msg('的确很重要', {icon: 1});
  107. }, function(){
  108. $(data.elem).prop('checked',false);
  109. });
  110. });
  111. });
  112. // });
  113. </script>

总结

今天这解课,让我学到了很多东西,实战部分和基础是紧紧联系的,基础不牢固,很多代码就不能理解,前面少的作业还是要好好补回来

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议