JS练习_鼠标事件
预览:
源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>鼠标事件</title>
<style>
.box{
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
let box = document.querySelector(".box");
box.onclick = function (){
console.log("被点击");
}
box.onmouseenter = function (){
console.log("鼠标移入")
}
box.onmousemove = function (){
console.log("鼠标移出")
}
</script>
</body>
</html>
把最实用的经验,分享给最需要的读者,希望每一位来访的朋友都能有所收获!