【问题标题】:When Automatically Refreshing a DIV, is it possible to not reload an Iframe within the DIV?自动刷新 DIV 时,是否可以不重新加载 DIV 内的 iframe?
【发布时间】:2012-03-25 07:25:37
【问题描述】:

我目前正在使用以下 JS 每 5 秒刷新一次页面上的 div

 if (auto_refresh === false) { 
   auto_refresh = setInterval(function (){$('#bottom_middle').load(thisurl + '&timer=' + new Date().getTime() + ' #bottom_middle' );}, 5000); 
 } else {
   clearInterval(auto_refresh); auto_refresh = false;
 }

在这个 div 中,用户可以使用 iframe 嵌入来自 Youtube 的视频。

是否可以在刷新 DIV 时不每次都重新加载 iframe?

【问题讨论】:

    标签: php jquery video refresh


    【解决方案1】:

    没有。如果您要刷新整个 div,那么 iframe 本身也会被刷新。您不能修剪/嫁接 DOM 树并说“替换此元素,除了我们要替换的元素的这个子元素”。

    您必须将更新拆分为多个部分,并仅更新 div 中不是 iframe 的部分。

    【讨论】:

      【解决方案2】:

      添加一个单独的容器来包装 div 中不是 iframe 的部分并加载到其中。如果您无法从服务器更改标记,您始终可以使用 jQuery wrap() 方法来包装您想要重新加载的元素,然后在新容器上使用您的 load() 方法

      http://api.jquery.com/wrap/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多