【发布时间】:2020-09-02 08:43:47
【问题描述】:
我有一个 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');
});
【问题讨论】:
-
错误是什么?如果您不告诉我们错误是什么,我们将无法帮助解决错误:)
-
糟糕!未捕获的类型错误:$(...).parent(...).parent(...).parent(...).find(...).attr(...).appendTo 不是函数
-
这是因为
attr('src')返回一个字符串。你不能在字符串上调用appendTo()。