js实现鼠标移动到div背景颜色变换,移开还原

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js重温</title>
	</head>
		
		<div id="sss" onmouseover = "over()" onmouseout="out()"                 
        style="width:100px;height:100px;color:red;background-color: green;color:red">鼠标不                            在上面
        </div>
		
        
	</body>
	<script>
		
		function over(){
			var x = document.getElementById("sss").innerHTML="鼠标在上面的样子";
			var x = document.getElementById("sss").style.color="pink";
			var x = document.getElementById("sss").style.backgroundColor="dodgerblue";
		}
		function out(){
			var x = document.getElementById("sss").innerHTML="鼠标不在上面";
			var x = document.getElementById("sss").style.color="red";
			var x = document.getElementById("sss").style.backgroundColor="green";
			
		}
		
		
	</script>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42630877/article/details/83095590