<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>qdabc.cn</title> <style> #myDiv{ width:200px; height:200px; background-color: black; } </style> </head> <body> <div id="myDiv"></div> </body> </html> <script type="text/javascript"> window.onload=function(){ var myDiv=document.getElementById("myDiv"); myDiv.onmousemove=function(){ this.style.backgroundColor="red"; } myDiv.onmouseout=function(){ this.style.backgroundColor="greenyellow"; } myDiv.onmousedown=function(){ this.style.backgroundColor="blue"; } myDiv.onmouseup=function(){ this.style.backgroundColor="pink"; } } </script>
欢迎分享本文,转载请保留出处:前端ABC » 鼠标移入悬停小方块背景变色