Home  >  Article  >  Web Front-end  >  Detailed explanation and examples of Javascript implementation of calculator time function (2)

Detailed explanation and examples of Javascript implementation of calculator time function (2)

高洛峰
高洛峰Original
2017-01-20 17:08:021243browse

Javascript Calculator:

Series of articles:

JS Detailed explanation and example code for implementing calculator (1)

Javascript Detailed explanation and example for implementing calculator time function (2) )

Javascript Calculator-> Add time Add time display in the upper left corner of the screen display area

The effect is as follows:

Javascript 实现计算器时间功能详解及实例(二)

Code

Initialize Javascript calculator

// 计算器初始化
Calculator.prototype.init = function () {
 this.addTdClick();
 
 // 时间显示
 this.showDate();
};

Time display

// 在屏显区左上角显示时间日期
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);
};

Time formatting

Date.prototype.format = function (dateStr){}

Get the time every second through the timer to display

Thanks for reading, I hope it can help everyone, thank you for your support of this site!

For more Javascript implementation details and examples of calculator time function (2), please pay attention to the PHP Chinese website for related articles!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn