我想要做的是顯示一個默認的字符串,當達到一定的時間時,它必須更新該字符串。該字符串將在後面有css的h1中更新。getTime JS代碼無法正常工作
這是我的代碼:
<h1 id="header" class="loginhead" ></h1>
<script>
//pu8t in onload
document.onload = setDateChange();
function setDateChange(){
// datestring format yyyy-mm-dd hh:mm:ss
String output ="Welcome to the All-Stars Summit Registration Site, Canada";
if (Date().getTime() > Date("2015-07-15 23:59:00").getTime())
{
output ="The All-Stars Summit Registration Site, Canada, is now closed";
}
document.getElementById('header').innerHTML = output; //change the html/text inside of the span with the id closed'.
}
setDateChange();
//figure out which date is next
//*********************
var timeTillNextDate = Date("2015-07-15 23:59:00").getTime();
var timeTillRun = Date("2015-07-15 23:59:00").getTime() - Date().getTime();
if(timeTillRun > 0){
setTimeout(setDateChange()), timeTillNextDate); //will wait to call changeHeader function until timeTillChange milliseconds have occured.
}
</script>
的的jsfiddle鏈接是在這裏:JSFiddle Code