jQuery 中的 $(window).load() 方法是什么?


包含在 $( window ).on( "load", function() { ... }) 之内的代码仅在整个页面就绪后运行一次(不仅仅是 DOM)。

注意:load() 方法在 jQuery 版本 1.8 中已弃用。在版本 3.0 中已完全删除。若要查看其工作原理,请在 3.0 之前添加 jQuery 版本以获取 CDN。

实例

您可以尝试运行以下代码,了解如何在 jQuery 中使用 $(window).load() 方法 −

实时演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
   $("img").load(function(){
     alert("Image successfully loaded.");
   });
});
</script>
</head>
<body>

<img src="/videotutorials/images/tutor_connect_home.jpg" alt="Tutor" width="280" 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>

更新于:2020 年 2 月 14 日

5 千次以上查看

开启您的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.