这些工作在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