时间:2021-07-01 10:21:17 帮助过:64人阅读
系列文章:
JS 实现计算器详解及实例代码(一)
Javascript 实现计算器时间功能详解及实例(二)
Javascript计算器 -> 添加时间在屏显区左上角添加时间显示
效果图如下:

代码
初始化Javascript 计算器
// 计算器初始化
Calculator.prototype.init = function () {
this.addTdClick();
// 时间显示
this.showDate();
};
时间显示
// 在屏显区左上角显示时间日期
Calculator.prototype.showDate = function () {
$("result-date").innerText = new Date().format("hh:mm:ss EEE yyyy-MM-dd");
var that = this;
if (this.timer) clearTimeout(this.timer);
this.timer = setTimeout(function(){
that.showDate();
}, 1000);
};
时间格式化
Date.prototype.format = function (dateStr){}通过定时器每隔一秒获取时间去显示
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
更多Javascript 实现计算器时间功能详解及实例(二)相关文章请关注PHP中文网!