通过 jQuery 在 youtube 嵌入的电影中启用自动播放 [英] Enable autoplay in youtube embedded movie by jQuery

查看:26
本文介绍了通过 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&amp;autoplay=0&amp;autohide=1" frameborder="0"></iframe>

正如您在 src 属性中看到的,有一个变量 autoplay=0.我在 jQuery 中编写了两行脚本,它应该将自动播放变量设置为 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 嵌入的电影中启用自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆