晨曦啊 晨曦啊

layer弹出层倒计时关闭的实现方法

in JavaScript 文章转载请注明来源!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
<script>
function func1() {
    var i = 9;
    var interval;
    layer.confirm('是否提交?', {
      btn: [i+1+'s后可提交','退出'], //按钮
      skin: 'layui-layer-molv',
      success: function(a,b){
        $(".layui-layer-btn0").css("backgroundColor","#92B8B1");
        var fn = function() {
  //       layer.title(i+' 秒后,系统将自动退出并关闭。',b);
          $(".layui-layer-btn0").text(i+'s后可提交');
          i--;
        };
        interval = setInterval(function(){
            fn();
            if(i === 0){
              $(".layui-layer-btn0").css("backgroundColor","#019F95");
              $(".layui-layer-btn0").text('提交');
              clearInterval(interval);
            }
          }, 1000);
      },
      end:function(){
        clearInterval(interval);
      }
      }, function(){
        if(i<=0) {
             layer.msg('已提交', {icon: 1});
          }
    
      }, function(){
        clearInterval(interval);
         layer.msg('已关闭', {icon: 1});
      
      });
  }
</script>
<button id="func1" onclick="func1();">询问框</button>
</body>
</html>
请输入图片描述

来源:https://www.jb51.net/article/171043.htm

jrotty WeChat Pay

微信打赏

jrotty Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

JavaScript
发表新评论
前篇 后篇
雷姆
拉姆