是否可以检测何时通过jQuery事件加载图像?

要使用jQuery检测图像的加载,请使用load()事件处理程序。

注意load()jQuery 1.8版中不推荐使用该方法。在3.0版中将其完全删除。要查看其工作原理,请在3.0之前添加CDN的jQuery版本。

示例

您可以尝试运行以下代码,以了解如何检测图像加载时间:

<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("img").load(function(){
        alert("图像成功加载。");
    });
});
</script>
</head>
<body>

<img src="/videotutorials/images/tutor_connect_home.jpg" alt="Tutor" width="304" height="236">

<p><strong>Note:</strong> The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.</p>

</body>
</html>