Love beautiful code? We do too.
.mouseleave(): Ràng buộc một xử lý tới một sự kiện mouseleave (di chuyển chuột ra khỏi thành phần), hoặc kích hoạt sự kiện mouseleave lên một thành phần.
Khác biệt giữa mouseleave và mouseout là:
Xem ví dụ để hiểu rõ mouseleave và mouseout
Sự khác biệt khi có sự di chuyển lên thành phần con.
Đã được thêm vào từ phiên bản 1.0
.mouseleave()
$('img').mouseleave();
.mouseleave(function(){...})
$('img').mouseleave(function(){
alert('Bạn vừa di chuyển chuột ra khỏi thành phần');
});
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('img').mouseleave(function(){
$(this).css('border','5px solid green');
});
$('button').click(function(){
$('img').mouseleave()
});
});
</script>
</head>
<body>
<img src="https://hoclaptrinh.vn/themes/client/img/code-screen.jpg"/>
<button>Click</button>
</body>
</html>
Hiển thị trình duyệt:
Khi click vào button, ta đã kích hoạt được giá trị mouseleave vào <img />
, giống như vừa di chuyển chuột ra khỏi <img />
.
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('img').mouseleave(function(){
$(this).css('border','5px solid green');
});
});
</script>
</head>
<body>
<img src="https://hoclaptrinh.vn/themes/client/img/code-screen.jpg"/>
</body>
</html>
Hiển thị trình duyệt:
Khi di chuyển chuột ra khỏi <img />
ta sẽ thấy được kết qủa.
Hoclaptrinh.vn © 2017
From Coder With
Unpublished comment
Viết câu trả lời