Логин:

Пароль:

Форумы
Общие вопросы
Document Object Model
Обсуждаем конференцию
Web Usability (test)

Общие вопросы

sergey

Не могу понять почему при выполнении моего скрипта, при прокрутке дат, IE6 (WinXP) иногда виснет или падает с недопустимой ошибкой. При этом с Opera 7 все в порядке.

<style>

#div_datebox {

position: absolute;
visibility: hidden;
}

</style>

<script>

var month_label =
new Array('Январь',
'Февраль',
'Март',
'Апрель',
'Май',
'Июнь',
'Июль',
'Август',
'Сентябрь',
'Октябрь',
'Ноябрь',
'Декабрь');

var currentDate = new Date(),
workDate = new Date(), showDate = new Date();

workDate.setDate(workDate.getDate() + 2);

var datebox_isshow = false;

function compareDate(date1, date2) {

if ((date1.getYear() == date2.getYear()) &&
(date1.getMonth() == date2.getMonth()) &&
(date1.getDate() == date2.getDate())) return true;
else return false;
}

function get_normalDay(value_date) {

var ret = value_date.getDay() - 1;
if (ret == -1) ret = 6;
return ret;
}

function get_normalYear(value_date) {

var ret = value_date.getYear();
if (ret - 1900 < 100) ret += 1900;
return ret;
}

function clickDatebox() {

showDate = new Date(workDate);

if(!datebox_isshow) {

prepareCalendar();

document.all['div_datebox'].style.top =
window.event.srcElement.offsetTop +
window.event.srcElement.offsetHeight;

document.all['div_datebox'].style.left =
window.event.srcElement.offsetLeft;

document.all['div_datebox'].style.visibility = 'visible';
datebox_isshow = true;

} else {

if(datebox_isshow) {
document.all['div_datebox'].style.visibility = 'hidden';
datebox_isshow = false;
}
}

return false;
}

function clickMonthLeft() {

if ((get_normalYear(showDate) == 1990) &&
(showDate.getMonth() == 0)) return false;

showDate.setMonth(showDate.getMonth() - 1);

prepareCalendar();

return false;
}

function clickMonthRight() {

if ((get_normalYear(showDate) == 2020) &&
(showDate.getMonth() == 11)) return;

showDate.setMonth(showDate.getMonth() + 1);

prepareCalendar();

return false;
}

function clickYear() {

showDate.setYear(selectYear.value);

prepareCalendar();

return false;
}

function clickMonth() {

showDate.setMonth(selectMount.value);

prepareCalendar();

return false;
}

function clickDay(y, m, d) {
alert(y + ' ' + m + ' ' + d);
}

function prepareCalendar() {

var inner_showDate = new Date(showDate);

var showMonth = inner_showDate.getMonth();

var content =
'<input id=button_datebox type=button value="<<<" onclick="return clickMonthLeft();">';

content += '<select name=selectMount onchange="return clickMonth();">';
var index;
for (index = 0; index < month_label.length; index++) {

content += '<option value=' + index;

if (showMonth == index) content += ' selected';
content += '>' + month_label[index] + '</option>';

}
content += '</select>';

content += '<select name=selectYear onchange="return clickYear();">';
var index;

for (index = 1990; index <= 2020; index++) {

content += '<option value=' + index;

if (get_normalYear(inner_showDate) == index) content += ' selected';
content += '>' + index + '</option>';

}
content += '</select>';

content +=
'<input id=button_datebox type=button value=">>>" onclick="return clickMonthRight();">';

content += '<table bgcolor=#eeeeee>';

content += '<tr>';

for (index = 0; index < 7; index++) {
switch(index) {
case 0: content += '<td>Пн</td>'; break;
case 1: content += '<td>Вт</td>'; break;
case 2: content += '<td>Ср</td>'; break;
case 3: content += '<td>Чт</td>'; break;
case 4: content += '<td>Пт</td>'; break;
case 5: content += '<td style="color:red">Сб</td>'; break;
case 6: content += '<td style="color:red">Вс</td>'; break;
}
}

content += '</tr>';

inner_showDate.setDate(1);
inner_showDate.setDate(1 - get_normalDay(inner_showDate));

var style_content = '';

do {
content += '<tr>';

for (index = 0; index < 7; index++) {

style_content = '';

if (inner_showDate.getMonth() == showMonth) {

if (compareDate(currentDate, inner_showDate))
style_content += 'background-color:green;';
else
if (compareDate(workDate, inner_showDate))
style_content += 'background-color:blue;';

if (get_normalDay(inner_showDate) == 5 ||
get_normalDay(inner_showDate) == 6)
style_content += 'color:red;';

if (style_content.length != 0)
style_content = ' style="' + style_content + '"';
}

content += '<td' + style_content + '>';

if (inner_showDate.getMonth() == showMonth)
content +=
'<a href="" onclick="clickDay(' +
get_normalYear(inner_showDate) + ',' +
inner_showDate.getMonth() + ',' +
inner_showDate.getDate() + '); return false;">' +
inner_showDate.getDate() +
'</a>';
else
content += '&nbsp;';

content += '</td>';

inner_showDate.setDate(inner_showDate.getDate() + 1);
}

content += '</tr>';

} while (inner_showDate.getMonth() == showMonth);

content += '</table>';

document.all.div_datebox.innerHTML = content;
}

</script>

<div id=div_datebox></div>


<br>
<br>
<br>
<br>
<br>
<center>
<input id=button_datebox type=button value=213 onmousedown="clickDatebox();">
<center>
СообщениеАвторДата
Sergey28.07.2003 18:28
ray17.09.2003 19:06