JAVA全系列 教程
3762个小节阅读:7093.8k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
选择器
DOM操作
CSS操作
事件处理
绑定事件处理器 .on() .one() .off()
鼠标事件
遍历
动画
为 JavaScript 的"click" 事件绑定一个处理器,或者触发元素上的 "click" 事件
xxxxxxxxxx
$("#btn").click(function() {
alert("点击事件");
});
将二个事件函数绑定到匹配元素上,分别当鼠标指针进入和离开元素时被执行
xxxxxxxxxx
$("li").hover(
// 滑入
function () {
console.log("滑入")
},
// 滑出
function () {
console.log("滑出")
}
);
鼠标进入事件
xxxxxxxxxx
$("div").mouseenter(function(){
console.log("鼠标进入事件");
})
鼠标离开事件
xxxxxxxxxx
$("div").mouseleave(function(){
console.log("鼠标进入事件");
})
鼠标滑动事件
xxxxxxxxxx
$("div").mousemove(function(){
console.log("鼠标进入事件");
})
鼠标进入事件(注:支持事件冒泡)
xxxxxxxxxx
<!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>
<script src="./js/jquery-3.6.0.min.js"></script>
<style>
.container{
width: 200px;
height: 200px;
background-color: red;
}
.box{
width: 100px;
height: 100px;
background-color: green;
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
<script>
$(".container").mouseover(function(){
console.log("鼠标进入事件container");
})
$(".box").mouseover(function(){
console.log("鼠标进入事件box");
})
</script>
</body>
</html>
鼠标离开事件(注:支持事件冒泡)
xxxxxxxxxx
<!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>
<script src="./js/jquery-3.6.0.min.js"></script>
<style>
.container{
width: 200px;
height: 200px;
background-color: red;
}
.box{
width: 100px;
height: 100px;
background-color: green;
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
<script>
$(".container").mouseout(function(){
console.log("鼠标离开事件container");
})
$(".box").mouseout(function(){
console.log("鼠标离开事件box");
})
</script>
</body>
</html>
实时效果反馈
1. 下列哪个事件可以完成鼠标进入与滑出的监听:
A click()
B hover()
C mouseenter()
D mouseleave()
答案
1=>B