当onmouseover
div将背景更改为黑色
时,当onmouseout
我想将背景更改为旧颜色时,在这种情况下是红色代码中没有指定红色我该怎么办?
<style type="text/css">
.test {
background: red;
}
</style>
<div onmouseover="onmouseover_fn()" onmouseout="onmouseout_fn()" class="test" id="test">TEST</div>
<script>
function onmouseover_fn(){
document.getElementById("test").style.backgroundColor = "#000000";
}
function onmouseout_fn(){
document.getElementById("test").style.backgroundColor = "unset";
}
</script>
最佳答案
使用css pusedo类:hover
.test {
background: red;
}
.test:hover {
background: black;
color: white;
}
<div class="test" id="test">TEST</div>
关于javascript - 使用 onmouseout javascript 时如何将背景设置为旧颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51855041/