php - 如果内容中存在 iframe,如何将 iframe / 视频替换为另一个 div?
问题描述
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>
推荐阅读
- reactjs - React.js:从 useState 数组中获取特定字符串
- amazon-web-services - 将 log4j2 与 AWS Lambda 一起使用
- android - Android上的自定义导航抽屉
- python - 烧瓶 | Python脚本输出不连续显示
- python-3.x - 逐行读取操作并为每一行生成 eval()
- firebase - 同时更新不同路径的 2 个字段是否算作 Cloud Firestore 中的 2 次写入?
- concurrency - 关于在cuda中修改标志数组的问题
- r - 从 github 安装包的问题
- python - 1 个列表中的 Python 父对象
- python - 在 Matplotlib 中绘制拟合。值错误:x 和 y 必须具有相同的第一维