html - 附加 iframe src
问题描述
我有一个 onclick 函数,我希望 iframe 附加到我网站中的另一个 div。因此,当用户单击“watch-youtube-video”时,它将从“youtube-video”中获取 iframe,并将 src 附加到“fixed-player”iframe src。
我曾尝试使用下面的 jQuery,但我遇到了错误。有人可以帮忙吗?
HTML
<div class="fixed-player"><iframe src=""></div>
<div class="span-row wow scale-anm all animated">
<div class="portal-img ">
<div class="youtube-video">
<iframe frameborder="0" height="100%" width="100%" src="https://youtube.com/embed/10zsTgv8MxA?autoplay=1&mute=1&controls=0&showinfo=0&autohide=1&loop=1" allowautoplay="" allowfullscreen="" data-origwidth="100%" data-origheight="100%" style="width: 0px;">
</iframe>
</div>
</div>
<div class="portal-cont ">
<div class="top-cont ">
<div class="main-button grey-btn watch-youtube-video">
Watch Video
</div>
</div>
</div>
</div>
jQuery
$('.watch-youtube-video').on('click', function(){
$('.overlay').fadeIn();
$('.youtube-viewer-pop').fadeIn();
$(this).parent().parent().parent().find("iframe").attr("src").appendTo('fixed-player');
});
解决方案
要设置src
jQuery 对象的属性,您应该改用该.attr()
方法,即.attr('src', <SOURCE>
:):
const src = $(this).parent().parent().parent().find("iframe")[0].src;
$('.fixed-player').attr('src', src);
推荐阅读
- r - 具有不完整和不规则时间变量的组滞后值
- centos7 - 另一个 Linux 用户的无限权限
- c# - 如何为 Outlook 约会设置时区。如果通过 EWS API 创建时
- android - 当应用程序不在前台时如何安排 WorkManager
- c# - 使用多个重载和默认参数调用特定的基本方法
- r - 如何解决在 R 包中使用 source() 导致的“字符”类型向量的“关闭”问题?
- lua - 计算网格上的实体位置(笛卡尔坐标)(实体和地砖大小不同)
- javascript - 如何在函数中等待获取函数?
- python - 如何在同一个 HTML 页面上显示来自两个不同模型的数据
- ubuntu - x86 NASM 程序集中的阶乘函数出错