分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

js页面倒计时

发布时间:2023-09-06 02:00责任编辑:白小东关键词:js
<!doctype html><html><head> ???<meta charset="utf-8"> ???<title>活动倒计时</title> ???<style> ???????* ???????{ ???????????margin:0; ???????????padding:0; ???????????list-style:none; ???????} ???????body ???????{ ???????????font-size:18px; ???????????text-align:center; ???????} ???????.time ???????{ ???????????height:30px; ???????????padding:200px; ???????} ???????a{ ???????????text-decoration: none; ???????????color: black; ???????????display: block; ???????????font-family: "宋体"; ???????????font-style: oblique; ???????} ???</style></head><body><div class="time"> ???<span id="view"></span> ???<a id="jump" href="http://www.baidu.com">立即报名</a></div><script src="js/jquery-1.7.2.js"></script><script> ???$(document).ready(function(){ ???????// ?stopFlag为定时任务对象 ???????var stopFlag = setInterval(function(){getDistanceTime(‘2018-06-10 21:34:30‘,‘view‘)},0); ???????function getDistanceTime(time,view){ ???????????var endTime= new Date(Date.parse(time.replace(/-/g, "/")));/*replace将时间字符串中所有的‘-‘替换成‘/‘,parse将时间格式的字符串转换成毫秒*/ ???????????var nowTime = new Date(); ???????????var distance =endTime.getTime() - nowTime.getTime();/*getTime把一个date对象转换成毫秒*/ ???????????var day = 0; ???????????var hour = 0; ???????????var minute = 0; ???????????var second = 0; ???????????if(distance >=0){ ???????????????day = Math.floor(distance/1000/60/60/24); ???????????????hour = Math.floor(distance/1000/60/60%24); ???????????????minute = Math.floor(distance/1000/60%60); ???????????????second = Math.floor(distance/1000%60); ???????????}else{ ???????????????stop(); // 终止定时任务 ???????????} ???????????$("#view").html(day + "天" + ?hour + "时" + minute + "分" + second + "秒") ???????} ???????function stop() { ???????????// 终止指定的定时任务 ???????????window.clearInterval(stopFlag); ???????????//$("#jump").attr("disabled"); ?// 去除属性 ???????????$("#jump").attr("href","#").click(function () { ???????????????alert("活动已经终止,请留意官网最新动态!"); ???????????}); ???????} ???});</script></body></html>

  

js页面倒计时

原文地址:https://www.cnblogs.com/nevegiveup/p/9186468.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved