jQuery 中的 $('iframe').ready() 方法如何工作?


以下是一個示例,其中 iframe 大小大於頁面。每當 iframe 載入時,我們都將使用 jQuery 滾動到頁面的頂部 -

示例

線上演示

<!DOCTYPE html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        $('iframe').ready(function(){
          $(window).scrollTop(0);
        });
      });
   });
   </script>
  </head>
<body>
  <iframe frameborder="2" height="900" id="iframe" align="top" src="https://www.qries.com" width="900" ></iframe><br>
  <button>Loop through each image</button>
</body>
</html>

更新時間: 20-Jun-2020

3K+ 瀏覽量

開啟你的 職業生涯

完成課程即可獲得認證

開始學習
廣告