Помогите разобраться с конструктором
Нужно написать функцию-конструктор, которая выводит текущее время. Вначале должен отображаться режим "short" - часы и минуты. По левому клику - режим "full" - часы, минуты и секунды. По правому клику с режима "short" или "full" на режим "date" - год, день и месяц? и с режима "date" в режим "short". Но у меня не отображается время, а выводит undefined. Не могу разобраться.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="clock.css"> <script type="text/javascript" src="test3.js"></script> <title>Timer</title> </head> <body> <div></div> </body> </html> window.addEventListener('load', function () { var timePlace = document.querySelector('div'), mode = 'short'; function RefreshTime (el) { this.dateAndTime = new Date(); this.year = this.dateAndTime.getFullYear(); this.month = this.dateAndTime.getMonth(); this.day = this.dateAndTime.getDay(); this.hours = this.dateAndTime.getHours(); this.minutes = this.dateAndTime.getMinutes(); this.seconds = this.dateAndTime.getSeconds(); this.addZero = function (number) { return (number < 10)? '0' + number: number; }; this.shortTimerMode = this.addZero(this.hours) + ':' + this.addZero(this.minutes); this.fullTimerMode = this.addZero(this.hours) + ':' + this.addZero(this.minutes) + ':' + this.addZero(this.seconds); this.dateTimerMode = this.addZero(this.month) + '/' + this.addZero(this.day) + '/' + this.year; el.innerHTML = this.shortTimerMode; this.checkMode = function () { if (mode === 'short') { el.innerHTML = this.shortTimerMode; } else if (mode === 'full') { el.innerHTML = this.fullTimerMode; } else { el.innerHTML = this.dateTimerMode; } }; this.switchToFull = function () { if (mode === 'short') { mode = 'full'; } else { mode = 'short'; } this.checkMode; }; this.switchToDate = function (e) { if (mode === 'date') { mode = 'short'; } else { mode = 'date'; } this.checkMode; e.preventDefault(); }; el.addEventListener('click', this.switchToFull, false); el.addEventListener('contextmenu', this.switchToDate, false); setTimeout(this.checkMode, 1000); return this; } var clock = new RefreshTime(timePlace); }); |
serhioses,
Пожалуйста, отформатируйте свой код! Для этого его можно заключить в специальные теги: js/css/html и т.п., например: [js] ... ваш код... [/js] О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting. |
Часовой пояс GMT +3, время: 03:34. |