【问题标题】:Dynamically loading iframes when a button is pressed按下按钮时动态加载 iframe
【发布时间】:2017-12-03 14:25:27
【问题描述】:

我正在创建一个网页,我必须在 div 中加载 iframe。

<div class="sketchfab">
    <iframe class="myframe" src=""></iframe>
</div>

在它下面我有链接应该提供 iframe 的来源

<div class="container">
    <a href=#>A</a>
    <a href=#>B</a>
    <a href=#>C</a>
    <a href=#>D</a>
    And so on till Z
</div>

我该怎么做?
iframe 显示标志手势的 3D 动画。所以基本上当我按下A的超链接时,A的手势就会出现......等等......

【问题讨论】:

标签: javascript jquery html iframe


【解决方案1】:

HTML


<div class="">
    <a href="#" data-url="hMxGhHNOkCU">A</a>
    <a href="#" data-url="BWXggB-T1jQ">B</a>
    <a href="#" data-url="gqOEoUR5RHg">C</a>
    <a href="#" data-url="5GcQtLDGXy8">D</a>
    And so on till Z
</div>

还有 Javascript:

$(function() {
    $('a').click(function() {
    var _this = $(this),
            iframe = $('iframe');

    iframe.attr('src','https://www.youtube.com/embed/' + _this.attr('data-url'));
  });
});

您可以查看this Fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多