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

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

高洛峰
Release: 2017-01-20 17:08:02
Original
1273 people have browsed it

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();
};
Copy after login

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);
};
Copy after login

Time formatting

Date.prototype.format = function (dateStr){}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template