如何让mouseOver和mouseout无法在元素<div onmouseover="mouseOver()" >
document.getElementById('smallBox').addEventListener("onmouseover", function() {
document.getElementById('smallBox').style.color = "blue;"
});
document.getElementById('smallBox').addEventListener("onmouseout", function() {
document.getElementById('smallBox').style.color = "yellow;"
});
&#13;
#smallBox {
background-color: green;
width: 100px;
height: 100px;
}
&#13;
<div id="smallBox">hi</div>
&#13;
答案 0 :(得分:2)
事件的名称实际上是mouseover
和mouseout
。我必须改变的另一件事是颜色属性,它应该是"blue"
而不是"blue;"
document.getElementById('smallBox').addEventListener("mouseover", function() {
document.getElementById('smallBox').style.color = "blue";
});
document.getElementById('smallBox').addEventListener("mouseout", function() {
document.getElementById('smallBox').style.color = "yellow";
});
&#13;
#smallBox {
background-color: green;
width: 100px;
height: 100px;
}
&#13;
<div id="smallBox">hi</div>
&#13;
答案 1 :(得分:0)
在onload函数下为JS中的该元素添加事件处理程序。 document.getElementById("smallbox").addEventListener("mouseover", myFunction)
在加载DOM时需要调用此函数。
document.getElementById("smallbox").addEventListener("load", functionName)
Nd用于活动参考,请访问w3Schools