javascript å¦ä¹ ç¬è®°ï¼åï¼ å计æ¶ç¨åºä»£ç _åºç¡ç¥è¯
程序员文章站
2022-06-15 17:28:08
...
é¦å
çå
¨é¨å®æ´ä»£ç ï¼
[Ctrl+A å ¨é 注:å¦éå¼å ¥å¤é¨Jséå·æ°æè½æ§è¡]
htmlé¨å代ç ï¼
å¯å¨ææ¬æ¡ä¸è¾å ¥å计æ¶çæ¶é´ï¼å¦æå½åæ¶é´å°äºæªæ¢æ¶é´ï¼åæ£å¸¸è¿åï¼åä¹ï¼åè¿åè·ç¦»æªæ¢æ¥æå°ç°å¨çæ¶é´
javascripté¨å代ç ï¼
function countDown(endDate) {
var now = new Date();
var deadtime = document.getElementById(endDate);
var deadline = new Date(deadtime.value);
//æ¬å°æ¶é´ä¸æ ¼æå¨æ²»æ åæ¶é´ (GMT) çåéå·®
var timeDiff = now.getTimezoneOffset();
//æ¤å¤æäºä¸è§£ï¼å¦ææåé差转åæ毫ç§åºè¯¥æ¯timeDiff*60*1000ï¼ä½æ¯è¿æ ·è¿åçæ°æ®ä¸æ£ç¡®ï¼
var leave = Math.abs(deadline.getTime() - now.getTime() + timeDiff*60);
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var countDay = Math.floor(leave/day);
//var countHour = Math.floor((leave - day*countDay)/hour); 两ç§è®¡ç®æè·¯
var countHour = Math.floor(leave/hour - countDay*24);
var countMinute = Math.floor(leave/minute) - countDay*24*60 - countHour*60;
var countSecond = Math.floor(leave/1000) - countDay*24*60*60 - countHour*60*60 - countMinute*60;
var outStr = "";
if(deadline outStr = "è·ç¦»"+deadtime.value+"å·²æ"+countDay+"天"+countHour+"å°æ¶"+countMinute+"å"+countSecond+"ç§";
} else {
outStr = "è·ç¦»"+deadtime.value+"è¿å·®"+countDay+"天"+countHour+"å°æ¶"+countMinute+"å"+countSecond+"ç§";
}
var showTime = document.getElementById("showTime");
showTime.innerHTML = outStr;
}
[Ctrl+A å ¨é 注:å¦éå¼å ¥å¤é¨Jséå·æ°æè½æ§è¡]
htmlé¨å代ç ï¼
å¯å¨ææ¬æ¡ä¸è¾å ¥å计æ¶çæ¶é´ï¼å¦æå½åæ¶é´å°äºæªæ¢æ¶é´ï¼åæ£å¸¸è¿åï¼åä¹ï¼åè¿åè·ç¦»æªæ¢æ¥æå°ç°å¨çæ¶é´
å¤å¶ä»£ç 代ç å¦ä¸:
javascripté¨å代ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
function countDown(endDate) {
var now = new Date();
var deadtime = document.getElementById(endDate);
var deadline = new Date(deadtime.value);
//æ¬å°æ¶é´ä¸æ ¼æå¨æ²»æ åæ¶é´ (GMT) çåéå·®
var timeDiff = now.getTimezoneOffset();
//æ¤å¤æäºä¸è§£ï¼å¦ææåé差转åæ毫ç§åºè¯¥æ¯timeDiff*60*1000ï¼ä½æ¯è¿æ ·è¿åçæ°æ®ä¸æ£ç¡®ï¼
var leave = Math.abs(deadline.getTime() - now.getTime() + timeDiff*60);
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var countDay = Math.floor(leave/day);
//var countHour = Math.floor((leave - day*countDay)/hour); 两ç§è®¡ç®æè·¯
var countHour = Math.floor(leave/hour - countDay*24);
var countMinute = Math.floor(leave/minute) - countDay*24*60 - countHour*60;
var countSecond = Math.floor(leave/1000) - countDay*24*60*60 - countHour*60*60 - countMinute*60;
var outStr = "";
if(deadline outStr = "è·ç¦»"+deadtime.value+"å·²æ"+countDay+"天"+countHour+"å°æ¶"+countMinute+"å"+countSecond+"ç§";
} else {
outStr = "è·ç¦»"+deadtime.value+"è¿å·®"+countDay+"天"+countHour+"å°æ¶"+countMinute+"å"+countSecond+"ç§";
}
var showTime = document.getElementById("showTime");
showTime.innerHTML = outStr;
}
上一篇: 人脸认证源码faceIdentify详解
下一篇: Photoshop 小鸟张嘴鸣叫动画
推荐阅读
-
js实现翻页后保持checkbox选中状态的实现方法_javascript技巧
-
JavaScript call apply使用 JavaScript对象的方法绑定到DOM事件后this指向问题_javascript技巧
-
JavaScript冒泡排序算法
-
目前流行的JavaScript库的介绍及对比_jquery
-
IE6、IE7中获取Button元素的值的bug说明_javascript技巧
-
理解Javascript_05_原型继承原理_javascript技巧
-
学习JavaScript正则表达式_javascript技巧
-
JavaScript操作DOM元素的childNodes和children区别_javascript技巧
-
Javascript中各种trim的实现详细解析_javascript技巧
-
javascript 模式设计之工厂模式学习心得_js面向对象