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.com/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 千次以上檢視

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告