php - 如果内容中存在 iframe,如何将 iframe/video 替换为另一个 div?

标签 php html

WordPress 网站。

我想要 jquery 或 php,或任何简单的解决方案,从 div id=content(如果存在)中获取 div,并将其放入 id=iframer div,同时在加载时删除 id=content。

<div id="iframer">
**/ I am waitting to get "<div class="video">All content </div>" inside me. /**
</div>

<div id="content">
<div class="video">
<iframe width="697" height="392" src="https://www.youtube.com/embed/xxxxxxx?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
</div>
</div>

一些脚本后的结果...

<div id="iframer">
<div class="video">
<iframe width="697" height="392" src="https://www.youtube.com/embed/xxxxxxx?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
</div>
</div>

<div id="content">
**/ Iframer stolen my content. /**
</div>

最佳答案

不确定为什么不能直接编辑 HTML 或生成此 HTML 的代码,但这是我使用 javascript/jQuery 的解决方案。

<script>
//A page can't be manipulated safely until the document is "ready."
$( document ).ready(function() {
  //Get the html content inside div with id='content'
  var myHtml = $( '#content' ).html();

  //Copy the HTML in the div with id='iframer'
  $( '#iframer' ).html( myHtml );

  //Delete the HTML content inside div with id='content'
  $( '#content' ).html( '' );
});
</script>

关于php - 如果内容中存在 iframe,如何将 iframe/video 替换为另一个 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55306810/

相关文章:

php - 没有正确重定向标题

php - 将 LOAD DATA UNFILE MySQL UPDATE 转换为 php

php - session_regenerate_id 导致返回两个 PHPSESSID cookie

html - CSS中从透明到颜色的渐变

javascript - 这个绝对定位的元素没有定位在它最近的祖先旁边,而是附加到文档主体,我想知道为什么

python - 从网页获取国际字符?

php - 如何从 mysql 中的日期加载 {html_select_date} 中的日期

php - 中途更改 fopen() 模式?

html - Facebook 共享数据 URI 图片

css - div 仅在一侧溢出?