Định nghĩa và sử dụng .mousedown() trong jQuery

.mousedown(): Ràng buộc một xử lý tới một sự kiện mousedown (click chuột), hoặc kích hoạt sự kiện mousedown lên một thành phần.

Cấu trúc .mousedown() trong jQuery

Đã được thêm vào từ phiên bản 1.0

.mousedown()

$('input').mousedown();
.mousedown(function(){...})

$('input').mousedown(function(){
    alert('Bạn vừa click chuột');
});

.mousedown()

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').mousedown(function(){
        $(this).css('border','5px solid green');
    });
    $('button').click(function(){
        $('img').mousedown()
    });
});
</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ị mousedown vào <img />, giống như vừa click vào <img />.

.mousedown(function(){...})

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').mousedown(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 click vào <img /> ta sẽ thấy được kết qủa.

Viết câu trả lời

Drop Images

0 Bình luận