我最近發了一篇文章,但我說了我的問題(錯誤)和東西,並刪除它,所以我再次去。我需要一些javascript協助
好吧,我有一個學校項目的網站,這很匆忙,因爲我們即將交付,我們只是添加一些視覺材料,使網站看起來更漂亮,更具吸引力,所以是的,它的作業/項目。因此,我去了一個時鐘代碼的地方,我設法開始工作,並且我沒有完全理解它的每一點。 下面是代碼:
tday =new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
function GetClock(){
d = new Date();
nday = d.getDay();
nmonth = d.getMonth();
ndate = d.getDate();
nyear = d.getYear();
nhour = d.getHours();
nmin = d.getMinutes();
nsec = d.getSeconds();
if(nyear<1000) nyear=nyear+1900;
if(nhour == 0) {ap = " AM";nhour = 12;}
else if(nhour <= 11) {ap = " AM";}
else if(nhour == 12) {ap = " PM";}
else if(nhour >= 13) {ap = " PM";nhour -= 12;}
if(nmin <= 9) {nmin = "0" +nmin;}
if(nsec <= 9) {nsec = "0" +nsec;}
document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+", "+nyear+" "+nhour+":"+nmin+":"+nsec+ap+"";
setTimeout("GetClock()", 1000);
}
window.onload=GetClock;
<h:body onload="updateClock(); setInterval('updateClock()', 1000)">
<h5 id="clockbox">x</h5>
好吧,因爲我與JavaScript的經驗是很可怕的,我不明白的IF-句子,像什麼1000和1900意味着這種情況的? AP從哪裏來?在nmin和nsec中,我明白髮生了什麼,但無法解釋...還有clockbox,在這種情況下innerHTML是什麼?
我希望這篇文章和解釋是更好..
他們的意思是1000和1900.他們是數字。 ap是一個變量。 – 2014-12-03 22:39:59
您應該考慮使用正確的縮進,這些單行程不會提高可讀性。 – martijnn2008 2014-12-03 22:41:01