所以我有一個腳本,基本上刷新時間一致,所以用戶看到的時間與秒/分鐘/小時等加起來。<script>打開頁面時並不總是加載
出於某種原因,有時當我加載它的工作頁面,但大部分時間沒有。這是非常不尋常的,我想知道是否有人會有輸入。
爲了造型的目的,em標籤真的需要留在h1中。
這裏是我的代碼:
<head>
<link rel="stylesheet" type="text/css" href="styling.css">
<h1>The Trade Shack<em id="demo"></em></h1>
<title>Homepage</title>
<script>
function getCurrentDate(){
var fullDate = new Date();
var day = fullDate.getDay();
var stringDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var month = fullDate.getMonth();
var stringMonth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var numDay = fullDate.getDate();
var year = fullDate.getFullYear();
var hour = fullDate.getHours();
var minute = fullDate.getMinutes();
var second = fullDate.getSeconds();
document.getElementById("demo").innerHTML = stringDays[day] + ", " + stringMonth[month] + " " + numDay + ", " + year + ", " + hour + ":" + minute + ":" + second;
}
setInterval(getCurrentDate,1000);
</script>
</head>
纏上window.onload..It的代碼應工作 – Geeky
只是調用的window.onload內的setInterval ...這將很好地工作 – Geeky
不使用H1,...的頭部片段。頭部片段應該只包含鏈接,腳本,元或標題等元素。其他所有東西都應該用在車身標籤上。您可以使用https://validator.w3.org/驗證您的標記,例如 –