次の JavaScript は Firefox では機能しません。表示される唯一のデバッグ エラーは、var month = '.date(' m', $time).'; ライン。
このコードは Internet Explorer と Chrome で完全に機能しますが、Firefox でのみ機能しませんが、警告ボックスを使用して通常停止する行を強調表示しても、問題に関するヒントは得られません。
var hours = '.date('G', $time).';
var minutes = '.date('i', $time).';
var seconds = '.date('s', $time).';
var day = '.date('d', $time).';
var month = '.date('m', $time).';
var year = '.date('o', $time).';
function getDayCount(monthIndex, yearIndex)
{
switch ( monthIndex )
{
case 0: return 31;
case 1: return isLeapYear(yearIndex) ? 29 : 28;
case 2: return 31;
case 3: return 30;
case 4: return 31;
case 5: return 30;
case 6: return 31;
case 7: return 31;
case 8: return 30;
case 9: return 31;
case 10: return 30;
case 11: return 31;
}
return 31;
}
function isLeapYear(yearIndex)
{
return new Date(yearIndex, 2-1, 29).getDate() == 29;
}
function getDayName(year, month, day, hours, minutes, seconds)
{
var d = new Date(year, month, day, hours, minutes, seconds, 0);
var weekday= new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
return weekday[d.getDay()];
}
function updateClock()
{
window.seconds++;
if ( window.seconds == 60 ) {
window.minutes++;
window.seconds = 0;
}
if ( window.minutes == 60 ) {
window.hours++;
window.minutes = 0;
}
if ( window.hours == 24 ) {
window.day++;
window.hours = 0;
}
if ( (window.day - 1) == getDayCount(window.month - 1, window.year) ) {
window.month++;
window.day = 1;
}
if ( window.month == 12 ) {
window.year++;
window.month = 1;
}
var hourString = window.hours.toString();
var minuteString = window.minutes.toString();
var secondsString = window.seconds.toString();
var dayString = window.day.toString();
var monthString = window.month.toString();
var yearString = window.year.toString();
if ( minuteString.length < 2 )
minuteString = "0".concat(minuteString);
if ( hourString.length < 2 )
hourString = "0".concat(hourString);
if ( secondsString.length < 2 )
secondsString = "0".concat(secondsString);
if ( dayString.length < 2 )
dayString = "0".concat(dayString);
if ( monthString.length < 2 )
monthString = "0".concat(monthString);
document.getElementById("hour").innerText = hourString;
document.getElementById("minute").innerText = minuteString;
document.getElementById("second").innerText = secondsString;
document.getElementById("day").innerText = dayString;
document.getElementById("month").innerText = monthString;
document.getElementById("year").innerText = yearString;
document.getElementById("dayName").innerText = getDayName(year, month - 1, day, hours, minutes, seconds);
}
function init()
{
window.setInterval(function(){updateClock()}, 1000);
}
関連する HTML:
<h2>Live Chat - <span id="hour"></span>:<span id="minute"></span>:<span id="second"></span> <span id="dayName"></span> <span id="day"></span>/<span id="month"></span>/<span id="year"></span></h2>
本体の初期化:
<body onload="javascript:init();">