Demonstration effect
When the mouse is moved up, the color is displayed in red; when the mouse is moved away, the color is displayed in black.
Get the id object: document.getElementById()
Move the mouse up: onmouseover
Mouse out: onmouseout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box1{
height: 30px;
text-align: center;
font: 30px/30px "楷体";
}
</style>
</head>
<body>
<div id="box1">
锣鼓一响,黄金万<span id="span">两</span>
</div>
<script>
document.getElementById("box1").onmouseover = function(){
document.getElementById("span").style.color = "red";
};
document.getElementById("box1").onmouseout = function(){
document.getElementById("span").style.color = "#000";
};
</script>
</body>
</html>