使用layui的layer组件做弹出层的例子

前端之家收集整理的这篇文章主要介绍了使用layui的layer组件做弹出层的例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

官方文档地址: http://www.layui.com/doc/modules/layer.html

本例演示效果

使用layui的layer组件做弹出层的例子


当点击申请提现时,出现申请提现框,并根据用户输入进行一些判断,给出友好提示,比如:

使用layui的layer组件做弹出层的例子


代码实现:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <Meta charset="UTF-8">
  5. <title>弹出层</title>
  6. <link rel="stylesheet" href="/static/layui/css/layui.css" rel="external nofollow" rel="external nofollow" >
  7. <script src="/static/layui/jquery.min.js"></script>
  8. </head>
  9. <body>
  10. <span id="pro" ><font size="10">申请提现</font></span>
  11. </body>
  12.  
  13. <script src="/static/layui/layui.js"></script>
  14. <script type="text/javascript">
  15.  
  16. $('#pro').on('click',function(){
  17. //提现弹窗之前进行一定判断伪代码
  18. //上述条件符合之后,弹出提现弹窗
  19. layui.use('layer',function() {
  20. var layer = layui.layer;
  21. layer.open({
  22. type: 2,// skin: 'layui-layer-molv',title: '申请提现',content:['/kk.PHP','no'],//不允许出现滚动条
  23. area:['600px','400px']
  24. });
  25. });
  26.  
  27. // });
  28. })
  29.  
  30. </script>
  31. </html>

kk.PHP

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <Meta charset="UTF-8">
  5. <title>Document</title>
  6. <link rel="stylesheet" href="/static/layui/css/layui.css" rel="external nofollow" rel="external nofollow" >
  7. <script src="/static/layui/jquery.min.js"></script>
  8. <style type="text/css">
  9. .aa{margin-top: 7%; font-size: 14px;}
  10. .bb {margin-top: 10%;}
  11. .aa .cc{
  12. float: right;
  13. margin-top: -11px;
  14. position: absolute;
  15. right: 30px;
  16. top: 50%;
  17. }
  18. .aa .account{
  19. border: 1px solid #10ad15;
  20. color:#10ad15;
  21. border-radius: 4px;
  22. padding: 20px;
  23. position: relative;
  24. }
  25. .txt{width: 410px; margin:30px; font-size: 16px; color: #333;}
  26. .layui-btn {
  27. display: inline-block;
  28. height: 38px;
  29. line-height: 38px;
  30. padding: 0 18px;
  31. background-color: #ffa751;
  32. color: #fff;
  33. text-align: center;
  34. border: none;
  35. border-radius: 2px;
  36. cursor: pointer;
  37. font-size: 16px;
  38. vertical-align: middle;
  39. margin-left: 25px;
  40.  
  41. }
  42. input[type="text"]{
  43. word-wrap: break-word;width: 240px;height: 38px;
  44. border-radius: 4px; padding: 0 5px;border: 1px solid #ddd;
  45. display:inline-block; margin:0px 10px;
  46. }
  47.  
  48. </style>
  49. </head>
  50. <body>
  51.  
  52. <!--输入提现金额浮层-->
  53. <div>
  54. <div class="txt">
  55. <span class="bb">输入提现金额</span>
  56. <input id="money_request" type="text" placeholder="最多可提现0.00元" maxlength="15">
  57. <div class="aa">
  58. <p>提现到建设银行</p>
  59. <div class="account">我的建设银行(546513212315451)<i class="cc"></i></div>
  60. </div>
  61. </div>
  62.  
  63. </div>
  64. <div class="layui-btn" id="layui-btnn">确认提现</div>
  65.  
  66. </body>
  67. <script src="/static/layui/layui.js"></script>
  68. <script type="text/javascript">
  69. $("#layui-btnn").on('click',function(){
  70. layui.use('layer',function() {
  71. var layer = layui.layer;//引入layer组件
  72. var money_request=$('#money_request').val();//获取用户输入的提现金额'
  73.  
  74. //判断用户输入的提现金额是否为空
  75. if(money_request==''){
  76. layer.msg('请输入提现金额',{icon: 2});
  77. return false;
  78. }
  79.  
  80. //判断用户输入的提现金额是否大于等于500
  81. if(money_request<500){
  82. layer.msg('提现金额需要大于等于500哦',{
  83. // time: 20000,//20s后自动关闭
  84. btn: ['明白了','知道了']
  85. });
  86. return false;
  87. }
  88.  
  89. //判断用户的提现金额是否大于拥有的金额
  90. //从后台取出该用户拥有多少余额
  91. //这里假设是950
  92. if(money_request>950){
  93. layer.msg('提现金额不能大于您的余额哦',{icon: 5});
  94. return false;
  95. }
  96.  
  97. });
  98.  
  99. });
  100.  
  101. </script>
  102. </html>

注: 需要用到layui框架,下载到某个地址后,在引入时指向其即可.

layui框架下载地址:

http://www.layui.com/

layer这个组件确实很好用,主要是使用起来特别方便.

我本人比较常用的时layer.msg() 和 layer.alert() 以及 layer.open();

以上这篇使用layui的layer组件做弹出层的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

猜你在找的JavaScript相关文章