Javascript-форум (https://javascript.ru/forum/)
-   Javascript под браузер (https://javascript.ru/forum/css-html/)
-   -   ie и document.body.appendChild() (https://javascript.ru/forum/css-html/13962-ie-i-document-body-appendchild.html)

hohol 22.12.2010 11:06

ie и document.body.appendChild()
 
Доброго времени суток.
Вообщем суть проблемы такая:
пишу Датапикер для сайта, код:
var datapicker=
	{
	init:function()
		{
		calendar=document.createElement('table');
		with(calendar)
			{
			className="datapicker_calendar";
			appendChild(MYControl=document.createElement('tr'));
				with(MYControl)
					{
					appendChild(Month=document.createElement('th'));
					with(Month)
						{
						colSpan=4;
						appendChild(MonthControl=document.createElement('select'));
						MonthControl.appendChild(Jan=document.createElement('option'));
						with(Jan)
							{
							value=1;
							text="Январь";
							}
						MonthControl.appendChild(Feb=document.createElement('option'));
						with(Feb)
							{
							value=2;
							text="Февраль";
							}
						MonthControl.appendChild(Mar=document.createElement('option'));
						with(Mar)
							{
							value=3;
							text="Март";
							}
						MonthControl.appendChild(Apr=document.createElement('option'));
						with(Apr)
							{
							value=4;
							text="Апрель";
							}
						MonthControl.appendChild(May=document.createElement('option'));
						with(May)
							{
							value=5;
							text="Май";
							}
						MonthControl.appendChild(Jun=document.createElement('option'));
						with(Jun)
							{
							value=6;
							text="Июнь";
							}
						MonthControl.appendChild(Jul=document.createElement('option'));
						with(Jul)
							{
							value=7;
							text="Июль";
							}
						MonthControl.appendChild(Aug=document.createElement('option'));
						with(Aug)
							{
							value=8;
							text="Август";
							}
						MonthControl.appendChild(Sep=document.createElement('option'));
						with(Sep)
							{
							value=9;
							text="Сентябрь";
							}
						MonthControl.appendChild(Oct=document.createElement('option'));
						with(Oct)
							{
							value=10;
							text="Октябрь";
							}
						MonthControl.appendChild(Nov=document.createElement('option'));
						with(Nov)
							{
							value=11;
							text="Ноябрь";
							}
						MonthControl.appendChild(Dec=document.createElement('option'));
						with(Dec)
							{
							value=12;
							text="Декабрь";
							}
						}
					appendChild(Year=document.createElement('th'));
					with(Year)
						{
						colSpan=3;
						appendChild(YearControl=document.createElement('input'));
						with(YearControl)
							{
							setAttribute("onkeypress","keyCode=event.charCode?event.charCode:event.keyCode; if(keyCode!=8 && (keyCode<48 || keyCode>57))return false")
							style.width="3em";
							setAttribute("maxlength","4")
							}
						}
					}
			Weeks=new Array();
			for(n=0;n<5;n++)
				{
				lastWeek=document.createElement('tr');
				Weeks[n]=lastWeek;
				appendChild(lastWeek);
				with(lastWeek)
					{
					Days=new Array();
					for(nn=0;nn<7;nn++)
						{
						lastDay=document.createElement('td');
						Days[nn]=lastDay;
						appendChild(lastDay);
						with(lastDay)
							{
							className="datapicker_day";
							lastDay.innerHTML='&nbsp;';
							}
						}
					}
				}
			appendChild(Applier=document.createElement('tr'));
			}
		document.body.appendChild(calendar);
		datapicker.calendar=calendar;
		collection=document.getElementsByTagName('INPUT');
		for(n in collection)
			{
			element=collection[n];
			if(element.className && element.className.match(/^(.*[\s]+)*datapicker([\s]+.*)*$/i) && element.type && element.type=='text')
				{
				this.convert(element);
				}
			document.body.focus();
			}
		},convert:function(element)
		{
		element.readOnly=true;
		element.onfocus=function()
			{
			datapicker.showCalendar(this);
			};
		},showCalendar:function(element)
		{
		
		}
	}

Проблема в строке
document.body.appendChild(calendar);

Таблица не вставляется в ИЕ, причём если сделать после этой строки
document.body.innerHTML=document.body.innerHTML

таблица появляется (тоесть все предыдущие операции добавляют таблицу но не выводят), но ссылка на неё в данном объекте теряется.
подскажите как быть

ksa 22.12.2010 13:50

Цитата:

Сообщение от hohol
подскажите как быть

Как вариант просто начать сначала...
- Создать элемент
- Добавить его в боди

Если он таки создаётся - продолжать наращивать код, пока либо ошибка не появится (вот она причина)... Либо все "само" и сделается... :)

hohol 22.12.2010 16:29

С проблемой разобрался:
ИЕ не даёт прикреплять tr к table, только к tbody


Часовой пояс GMT +3, время: 23:13.