这是我的 HTML。
<html>
<head>
<style type="text/css">
.button {
background: url('images/1.png');
}
.button:hover {
background: url('images/2.jpg');
}
</style>
</head>
<body>
<img class="button" src="images/1.png">
</body>
</html>
文件存在,但它仍然不起作用。我做错了什么?
最佳答案
标准方法是 CSS:
input.mybutton { background-image: url('button.jpeg'); }
input.mybutton:hover { background-image: url('selectedButton.jpeg'); }
使用 JavaScript,您可以覆盖图像的 .src:
imageElement.src = 'selectedButton.jpeg';
关于css - 当我将鼠标悬停在图像上时,为什么我的图像没有变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2573682/