這些工作在JSFiddleandi張貼在我的original question的答案。我很難過,因爲我錯過了它在瀏覽器中不起作用。我知道這將是一個非常簡單的修復。提前致謝。HTML/CSS/JS初學者錯誤
HTML:
<div class="blackwrap">
<header class="blackbar">
<h2>Before he knew it, he couldn't see a thing.</h2>
<h4>He fumbled around for the <a id="flash">flashlight</a> on his phone.</h4>
</header>
</div> <!-- .blackwrap-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="script.js"></script>
</body>
CSS:
.blackbar {
background: black;
color: white;
}
.blackbar.lit {
background:yellow;
color:black;
}
的Javascript:
$("#flash").on("mouseover", function(){
$(".blackbar").addClass("lit");
}).on("mouseout", function(){
$(".blackbar").removeClass("lit")
});
代碼工作正常。確保腳本正確加載。 –
那究竟是什麼問題呢? jsfiddle似乎很好。查看[JavaScript錯誤控制檯](http://www.netmagazine.com/tutorials/javascript-debugging-beginners),並告訴你在那裏看到了哪些錯誤以及它們指向哪些行。 – JJJ
使用chrome瀏覽器檢查檢查元素識別錯誤並將其張貼在這裏 – Amerrnath