本文介绍了通过jQuery在YouTube嵌入式电影中启用自动播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码嵌入youtube电影:
I embedd youtube movies with the code below:
<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.
As you can see in src attribute there is a variable autoplay=0. I wrote two line script in jQuery which should set the autoplay variable to 1.
var title = $("iframe#ytplayer").attr("src");
title.replace("autoplay=0", "autoplay=1");
但是它不起作用.该如何正确完成?
But it doesn't work. How can this be done properly?
关于,大卫
推荐答案
您没有修改src属性.
You aren't modifying the src attribute.
$("iframe#ytplayer").attr("src", $("iframe#ytplayer").attr("src").replace("autoplay=0", "autoplay=1"));
这篇关于通过jQuery在YouTube嵌入式电影中启用自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!