【问题标题】:jQuery get YouTube video src from iframe codejQuery 从 iframe 代码中获取 YouTube 视频 src
【发布时间】:2015-12-25 20:45:50
【问题描述】:

我正在尝试从 iframe 嵌入代码中获取 youtube src 并将其作为变量传递。

例如,如果我的 youtube 嵌入代码是:

<iframe width=&quot;1024&quot; height=&quot;576&quot; src=&quot;https://www.youtube.com/embed/rfxESg1_hEA?feature=oembed&quot;frameborder=&quot;0&quot;allowfullscreen></iframe>

我正在尝试获取https://www.youtube.com/embed/rfxESg1_hEA

有没有办法用 jQuery 做到这一点?

【问题讨论】:

    标签: jquery html iframe youtube


    【解决方案1】:

    试试这个:

    var src = $("iframe").attr("src").split('?')[0];
    alert(src);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <iframe width=&quot;1024&quot; height=&quot;576&quot; src="https://www.youtube.com/embed/rfxESg1_hEA?feature=oembed&quot;frameborder=&quot;0&quot;allowfullscreen"></iframe>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 2014-05-26
      • 2018-02-07
      • 2015-10-23
      • 1970-01-01
      相关资源
      最近更新 更多