限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

jquery支持在线自定义日期时间的倒计时插件

所属分类: 网页特效-日期时间    2023-09-01 10:09:29

jquery支持在线自定义日期时间的倒计时插件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery支持在线自定义日期时间的倒计时插件(共3个文件)

    • index.html

使用方法

$(document).ready(function () {

  $(".limit-button").on("click", function () {
    $('.limit').css("display", "none");
    $(".repeat").css("display", "none");
    $("form").append(`<input class="datetime-local" type="datetime-local">`);
    $(".datetime-local").insertBefore(".begin");
    $(".begin").css("display", "flex");
  });
  $(".repeat-button").on("click", function () {
    $('.repeat').css("display", "none");
    $(".limit").css("display", "none");
    $("form").append(`<input class="text" type="text" placeholder="Please type the number of days to countdown.">`);
    $(".text").insertBefore(".begin");
    $(".begin").css("display", "flex");
  });

  $("form").on("submit", function (e) {
    e.preventDefault();

    const typeInput = $("input")[0].type;
    const userInput = $("input").val();
    let seconds;

    if (typeInput == "text") {
      if (userInput == "" || isNaN(userInput)) {
        alert("请输入有效的日期时间");
      } else if (!isNaN(userInput)) {
        seconds = parseInt(userInput) * 86400;
        console.log(seconds);
      }
    } else {
      if (userInput == "") {
        alert("请输入有效的日期时间");
      } else {
        const date = new Date(userInput);
        const now = new Date();
        seconds = parseInt((date.getTime() - now.getTime()) / 1000);
        console.log(seconds);
      }
    }

    if (!seconds || seconds < 0) {
      alert("请输入有效的日期时间");
    } else {
      let days, hours, minutes;

      if (typeInput == "text") {
        days = Math.floor(seconds / (3600 * 24)) - 1;
        hours = 23;
        minutes = 59;
        seconds = 59;
      } else {
        days = Math.floor(seconds / (3600 * 24));
        seconds -= days * 3600 * 24;
        hours = Math.floor(seconds / 3600);
        seconds -= hours * 3600;
        minutes = Math.floor(seconds / 60);
        seconds -= minutes * 60;
      }

      $(`.${typeInput}`).remove();
      $("button.begin").css("display", "none");
      $("form").append(`<button class="stop">停止倒计时</button>`);

      const validationPrint = (timeUnit) => {
        return timeUnit < 10 ? `0${timeUnit}` : timeUnit;
      };

      $("#seconds").text(validationPrint(seconds));
      $("#minutes").text(validationPrint(minutes));
      $("#hours").text(validationPrint(hours));
      $("#days").text(validationPrint(days));

      const changeTimeWithLimit = setInterval(() => {
        seconds -= 1;
        $("#seconds").text(validationPrint(seconds));
        if (seconds === 0 && minutes > 0) {
          seconds = 60;
          minutes -= 1;
          $("#minutes").text(validationPrint(minutes));
        }
        if (seconds === 0 && minutes === 0 && hours > 0) {
          seconds = 60;
          minutes = 60;
          hours -= 1;
          $("#hours").text(validationPrint(hours));
        }
        if (seconds === 0 && minutes === 0 && hours === 0 && days > 0) {
          seconds = 60;
          minutes = 60;
          hours = 24;
          days -= 1;
          $("#days").text(validationPrint(days));
        }
        if (seconds === 0 && minutes === 0 && hours === 0 && days === 0) {
          clearInterval(changeTimeWithLimit);
        }
      }, 1000);

      $(".stop").on("click", function () {
        clearInterval(changeTimeWithLimit);
        console.log(`stop`);
        $(".limit").css("display", "block");
        $(".repeat").css("display", "block");
        $(this).remove();

        $("#seconds").text("00");
        $("#minutes").text("00");
        $("#hours").text("00");
        $("#days").text("00");
      });
    }
  });
});

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 日期时间

jquery太阳系天体行星运动模拟时钟动画插件

一款富有创意的时钟模拟动画特效,太阳为轴心点,水星作为秒针,金星为分针。
  日期时间
 2404  0

jquery支持选择日期时间几点几分的弹出层插件

一个日期和时间选择器插件,它使用jQuery和moment.js JavaScript库在隐藏的输入字段中添加了一个非常好的多语言日期和时间选择弹出窗口。
  日期时间
 4333  0

jquery轻量级自定义倒计时插件

一个轻量级自定义的倒计时插件,页面显示距离活动开始还有多少天/小时/分钟/秒。
  日期时间
 4338  0

jquery自定义时间选择器插件

qcTimepicker是一个时间选择器插件,它可以自动将文本字段转换为具有自定义时间格式的下拉时间picker。可自定义设置最小时间和最大时间,以及step.
  日期时间
 5262  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论