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){}
通过定时器每隔一秒获取时间去显示
—————————————- END —————————————-

本文介绍了一个JavaScript计算器项目中如何在屏幕显示区左上角添加实时时间显示的功能。通过使用JavaScript的Date对象和setTimeout方法实现了每秒更新时间的效果。
7261

被折叠的 条评论
为什么被折叠?



