我收到以下錯誤:使用Javascript - 遺漏的類型錯誤:未能執行「的getComputedStyle」上「窗口」:參數1的類型不是「元素」
Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'
我有Stickyfill源的問題( https://github.com/wilddeer/stickyfill)
我試過更多的版本我仍然得到相同的錯誤。我的JavaScript源代碼看起來像這樣:
var a = document.getElementById('left');
Stickyfill.add(a);
爲什麼我得到這個錯誤,我該如何解決它?
編輯: 這是我的html頁面:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css-home.css">
<script type="text/javascript" src="stickyfill.js"></script>
<script type="text/javascript" src="js-home.js"></script>
</head>
<body>
<div id="container">
<div id="banner">
<img src="sigla.jpg">
</div>
<div id="container2">
<div id="left">
<nav>
<a target="ifr" href="">Home</a>
<a target="ifr" href="">Istoric</a>
<a target="ifr" href="echipa.html">Echipa</a>
<a target="ifr" href="">Galerie</a>
</nav>
</div>
<div id="right">
<iframe name="ifr" src="echipa.html" frameborder="0" ></iframe>
</div>
</div>
<div id="footer">
<p>CS MIOVENI</p>
</div>
</div>
</body>
</html>
以後編輯: 我已經解決了使用的window.onload這個問題對我的JavaScript文件
你什麼時候執行JS? – ste2425
JS在加載.html頁面時執行(我這麼認爲) –