基本上我想要一個實時鐘,每秒更新一次!我環顧四周,找不到有效的東西。這是我曾嘗試過的:每秒更新javascript時間
function doDate()
{
var str = "";
var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var now = new Date();
str += "Today is: " + days[now.getDay()] + ", " + now.getDate() + " " + months[now.getMonth()] + " " + now.getFullYear();
var updateTime = function() { setTimeout("doDate()", 1000); }
document.getElementById("todaysDate").innerHTML = str;
}
這似乎並不奏效!我認爲我在這裏做了些什麼?
此代碼沒有任何影響:'VAR錄入=函數(){setTimeout的( 「doDate()」,1000); }' – hindmost 2014-10-27 09:18:32
我把這個添加爲註釋,導致它的代碼審查問題比答案的一部分更多:爲什麼不使用'Date'對象並將其解析爲希望顯示它,而不是創建一個每次計時器滴答時都會有一堆數組? – Jite 2014-10-27 09:24:13