我知道这是一个非常基本的东西,但我无法使用javascript更改按钮背景颜色。我想用类改变它,所以我可以为多个类做它。 javascript确实链接到html。
按钮代码为:
<button class ="buttonlink" onmouseover='hoverOver()'onclick="location.href='aboutme.html'">About Me</button><br>
我尝试的功能是:
function hoverOver(){
var x = document.getElementsByClass('buttonlink');
alert("x");
}
我知道这个问题可能在之前被问过,但我看起来并且找不到任何直接联系的东西,我真的很陌生,并且不知道我在做什么。
答案 0 :(得分:0)
使用鼠标悬停更改按钮背景颜色不是通过Javascript完成的(尽管可以)。正确的方法是使用CSS:
a.button:hover
如果您希望在将鼠标悬停在屏幕的其他部分时更改按钮的背景,请使用javascript。
这是一个简单的例子:
a.button a:hover{
background: #FF0;
}