作用:将二个事件函数绑定到匹配元素上,分别当鼠标指针进入和离开元素时被执行(传两个参数)
【例】代码效果
代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 100px;
height: 100px;
background-color: darkcyan;
}
.active {
width: 105px;
height: 105px;
background-color: #424242;
}
</style>
</head>
<body>
<div></div>
</body>
<script src="./jquery.js"></script>
<script>
$('div').hover(function () {
$(this).addClass('active');
},function () {
$(this).removeClass('active');
})
</script>
</html>