還有很多其他的問題關於這個完全相同的錯誤,但我沒有找到任何解決方案。無法讀取屬性'樣式'null
下面是HTML:
<!DOCTYPE html>
<html>
<head>
<title>ChatRoom</title>
<link rel="stylesheet" href="css/style.css">
<link href='https://fonts.googleapis.com/css?family=Raleway:400,200' rel='stylesheet' type='text/css'>
<script src="js/main.js"></script>
</head>
<body>
<div id="container">
<div id="logo">
<a href="./">
<h1>ChatRoom</h1>
<h3>Basic Chatroom<h3>
</a>
</div>
<div id="joinForm">
<div class="tHeader">
<h2>Join A ChatRoom</h2>
</div>
<div class="formArea">
<form action="joinRoom.php" method="GET">
<h3>Name Of Room:</h3>
<input type="text" name="roomName" class="jmInput" placeholder="Name Of Room">
<h3 class="margin-top">Password:</h3>
<input type="text" name="roomName" class="jmInput" placeholder="Password">
<input type="submit" name="roomName" class="jmInput" value="Join ChatRoom">
</form>
</div>
</div>
</div>
</body>
</html>
這裏是JS:
window.onload = fadeIn();
function fadeIn() {
var el = document.getElementById('joinForm');
el.style.opacity = 0;
(function fade() {
var val = parseFloat(el.style.opacity);
if(!((val += .1) > 1)) {
el.style.opacity = val;
requestAnimationFrame(fade);
}
})();
}
顯然莫名其妙的document.getElementById( 'joinForm')爲空。我真的不知道我該如何解決這個問題。
任何幫助將大規模讚賞。在此先感謝:)