會提示錯誤:
Uncaught TypeError: Cannot set property 'innerHTML' of null
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>副本</title>
</head>
<body>
<span class="day"></span>
<script type="text/javascript">
var now = new Date();
var newday = now.getDay();
var oday = document.getElementById("day");
console.log(newday);
oday.innerHTML = newday;
</script>
</body>
</html>
getElementById 用錯了,你沒獲取到元素。