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

Có 2 cách sử dụng:

  • Load sự kiện javascript.
  • load dữ liệu từ server sau đó đặt HTML trở lại từ các thành phần được chọn.

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

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

.load(function(){...})

$('img').load(function(){...});
.load('url')

$('#test').load('/ajax/test.html');
.load('url',function(){...})

$('#test').load('/ajax/test.html',function(){...});

.load(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').load(function(){
        if($(this).height() > 100) {
            $(this).css('border','5px solid blue');
        }
    })
});
</script>
</head>

<body>
<p><img src="https://hoclaptrinh.vn/themes/client/img/code-screen.jpg" alt="" /></p>
<p><img src="https://media.hoclaptrinh.vn/images/html-thumb-5af0325166970.png" alt="" /></p>
</body>
</html>

Hiển thị

Viết câu trả lời

Drop Images

0 Bình luận