发布于 2023-12-14 23:15:15 浏览 638 次
<!DOCTYPE html>
<html>
<head>
<title>Mouse Events</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
.box {
width: 100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
$(document).ready(function() {
$('.box').mouseenter(function() {
// 鼠标经过时的处理逻辑
$(this).css('background-color', 'blue');
});
$('.box').mouseleave(function() {
// 鼠标离开时的处理逻辑
$(this).css('background-color', 'red');
});
});
</script>
</body>
</html>
这只是一个简单的示例,你可以根据实际需求来编写更复杂的鼠标经过事件处理逻辑。另外,确保在文档加载完成后再绑定事件处理函数,可以使用 $(document).ready() 或 $(function() { ... }) 来实现。