【问题标题】:Enable autoplay in youtube embedded movie by jQuery通过 jQuery 在 youtube 嵌入电影中启用自动播放
【发布时间】:2012-05-27 08:04:22
【问题描述】:

我使用以下代码嵌入了 youtube 电影:

<iframe id="ytplayer" type="text/html" width="840" height="470" src="http://www.youtube.com/embed/Bag1gUxuU0g?wmode=transparent&amp;autoplay=0&amp;autohide=1" frameborder="0"></iframe>

正如您在 src 属性中看到的,有一个变量 autoplay=0。我在 jQuery 中编写了两行脚本,应该将 autoplay 变量设置为 1。

var title = $("iframe#ytplayer").attr("src");
title.replace("autoplay=0", "autoplay=1");

但它不起作用。怎样才能正确地做到这一点?

问候, 大卫

【问题讨论】:

    标签: jquery youtube autoplay


    【解决方案1】:

    您没有修改 src 属性。

    $("iframe#ytplayer").attr("src", $("iframe#ytplayer").attr("src").replace("autoplay=0", "autoplay=1"));
    

    【讨论】:

    • 虽然这会导致 iframe 重新加载,但它不会使视频自动播放 :( 不知道为什么。
    • @JonathonHill 你成功了吗?
    猜你喜欢
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 2015-02-19
    • 1970-01-01
    相关资源
    最近更新 更多