Love beautiful code? We do too.
.mouseenter(): Ràng buộc một xử lý tới một sự kiện mouseenter (di chuyển chuột vào thành phần), hoặc kích hoạt sự kiện mouseenter lên một thành phần.
Khác biệt giữa mouseenter và mouseover là:
Đã được thêm vào từ phiên bản 1.0
.mouseenter()
$('img').mouseenter();
.mouseenter(function(){...})
$('img').mouseenter(function(){
alert('Bạn vừa di chuyển chuột');
});
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').mouseenter(function(){
$(this).css('border','5px solid green');
});
$('button').click(function(){
$('img').mouseenter()
});
});
</script>
</head>
<body>
<img src="https://hoclaptrinh.vn/themes/client/img/code-screen.jpg" alt="" />
<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ị mouseenter vào , giống như vừa di chuyển chuột vào .
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').mouseenter(function(){
$(this).css('border','5px solid green');
});
});
</script>
</head>
<body>
<img src="https://hoclaptrinh.vn/themes/client/img/code-screen.jpg" alt="" />
</body>
</html>
Hiển thị trình duyệt:
Khi di chuyển chuột vào <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