вызов функции-родителя
Помогите пожалуйста, написал календарик сначала в процедурном стиле - все работало, потом решил через ОО подход. Проблема такова - пр и нажатии на < > вызывается функция, которая описана внутри функции createTable. Она удаляет из DOM календарь, а потом заново его создает функцией createTable. Но в реале, при нажатии на эту стрелку выдает ошибка Uncaught TypeError: Object #<HTMLTableCellElement> has no method 'createTable'
ошибка в 20 и 39 строке Calendar.prototype.createTable = function(month,year){ this.nowY = year; this.nowM = month; var table = document.createElement('table'); table.id='calendar'; var tbody = document.createElement('tbody'); tr = this.appendElement(tbody,'tr'); // вывод левой стрелки var td = document.createElement('td'); this.appendText(td,'<'); td.id="go_left"; td.onclick = function(){ table.parentNode.removeChild(table); this.nowM--; if(this.nowM==(-1)){ this.nowM=11; this.nowY--; }; this.createTable(this.nowM,this.nowY); }; tr.appendChild(td); // вывод названия месяца и года var td = document.createElement('td'); this.appendText(td,this.months[this.nowM]+" "+this.nowY); td.colSpan="5"; tr.appendChild(td); // вывод правой стрелки td = document.createElement('td'); this.appendText(td,'>'); td.id="go_right"; td.onclick = function(){ table.parentNode.removeChild(table); this.nowM++; if(this.nowM==12){ this.nowM=0; this.nowY++; }; this.createTable(this.nowM,this.nowY); }; tr.appendChild(td); // расчет количества дней в году, день недели первого дня this.calc(); // вырисовка календаря var d=0; for(var i=1; i<this.rowsCount+2; i++){ var tr = document.createElement('tr'); tbody.appendChild(tr); //для заголовков таблицы for(var j=0; j<7; j++){ var td = document.createElement('td');; if(i==1){ td.style.backgroundColor = 'red'; this.appendText(td,this.days[j]); }else{ var text = document.createTextNode(new Date(this.nowY,this.nowM,2-this.firstDofM+d).getDate()); // дата, с которой будет начинаться календарь var temp = new Date(this.nowY,this.nowM,2-this.firstDofM+d); if( temp.getMonth() !== this.nowM){ td.style.backgroundColor = 'gray'; } if((temp.getMonth()== this.nowM) & (temp.getDate()==this.nowD)){ td.style.backgroundColor = 'green'; } td.appendChild(text); d++; }; tr.appendChild(td); }; }; table.appendChild(tbody); document.body.appendChild(table); }; |
|
ищу, как исправить оишбку
|
Кури сюда:
http://javascript.ru/forum/events/28...-funkcijj.html this не относится к прототипу функции, this относится к контексту вызова. Вроде бы this.createTable(this.nowM,this.nowY)при событии td.onclick сработает как: td.createTable(td.nowM,td.nowY) что несомненно вызовет ошибку |
Часовой пояс GMT +3, время: 01:50. |