我使用以下代码嵌入 YouTube 电影:
<iframe id="ytplayer" type="text/html" width="840" height="470" src="http://www.youtube.com/embed/Bag1gUxuU0g?wmode=transparent&autoplay=0&autohide=1" frameborder="0"></iframe>
正如您在 src 属性中看到的,有一个变量 autoplay=0。我在 jQuery 中编写了两行脚本,应将 autoplay 变量设置为 1。
var title = $("iframe#ytplayer").attr("src");
title.replace("autoplay=0", "autoplay=1");
但是这不起作用。如何才能正确完成此操作?
问候, 大卫
最佳答案
您没有修改 src 属性。
$("iframe#ytplayer").attr("src", $("iframe#ytplayer").attr("src").replace("autoplay=0", "autoplay=1"));
关于jquery - 通过 jQuery 在 YouTube 嵌入电影中启用自动播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10772538/