誰かが私になぜwindow.onload
aspxではうまくいくがxhtmlではうまくいかないのか説明してもらえますか?
このwindow.onload
例はaspxで正常に機能します。
<script type="text/javascript">
//<![CDATA[
//handles the collapse of submenu items on navigation side menu
function toggle() {
document.getElementById('node4').style.display = '';
}
window.onload = toggle;
//]]>
</script>
しかし、このwindow.onload
例はXHTML1.0strictでは機能しません。countDownClock
(ページが読み込まれたときにすぐには起動しません):
<script type="text/javascript">
//<![CDATA[
//handles the collapse of submenu items on navigation side menu
function countDownClock() {
today = new Date();
openingDay = new Date();
openingDay.setMonth(2, 23);
(today > openingDay) ? openingDay.setFullYear(2013) : openingDay.setFullYear();
openingDay.setHours(9, 0, 0, 0);
document.getElementById("mallclock").dayNow.value = showDate(today);
document.getElementById("mallclock").timeNow.value = showTime(today);
var daysLeft = dayDiff(today, openingDay);
var hoursLeft = hoursDiff(today, openingDay);
var minutesLeft = minutesDiff(today, openingDay);
daysLeft = ((hoursLeft - 24) >= 0) ? daysLeft + (hoursLeft / 24) : daysLeft;
hoursLeft = ((hoursLeft - 24) >= 0) ? hoursLeft - ((hoursLeft / 24) * 24) : hoursLeft;
hoursLeft = ((minutesLeft - 60) >= 0) ? hoursLeft + (minutesLeft / 60) : hoursLeft;
minutesLeft = ((minutesLeft - 60) >= 0) ? minutesLeft - ((minutesLeft / 60) * 60) : minutesLeft;
document.getElementById("mallclock").days.value = daysLeft;
document.getElementById("mallclock").hours.value = hoursLeft;
document.getElementById("mallclock").minutes.value = minutesLeft;
}
window.onload = countDownClock;
//]]>
</script>
countDownClock
1分後に表示されるように設定されているボディイベントのみを発生させます
<body onload = "setInterval('countDownClock()', 60000)">