Enable autoplay in youtube embedded movie by jQuery

廉价感情. 提交于 2019-12-05 00:51:41

问题


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&amp;autoplay=0&amp;autohide=1" frameborder="0"></iframe>

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?

Regards, David


回答1:


You aren't modifying the src attribute.

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


来源:https://stackoverflow.com/questions/10772538/enable-autoplay-in-youtube-embedded-movie-by-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!