随机youtube视频自动播放Javascript [英] Javascript random youtube video autoplay
本文介绍了随机youtube视频自动播放Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在页面加载时从选区中显示随机的YouTube视频。我发现下面的问题非常有用,但我无法弄清楚如何让它自动播放。我已经尝试添加
I need to display a random youtube video from a selection when the page loads. I found the question below very helpful however I can't figure out how to get it to autoplay. I've tried adding
& autoplay = 1
&autoplay=1
在视频[索引]之后,但我无法让它工作/不知道我是否把它放在错误的地方。任何帮助将不胜感激。
after "videos[index]" but I can't get it to work / don't know if I am putting it in the wrong place. Any help would be much appreciated.
$(document).ready(function() {
var videos = [
'pRpvdcjkT3k',
'Te4wx4jtiEA',
'efTj6UYzvk4'
];
var index=Math.floor(Math.random() * videos.length);
var html='<div id="video"><h3>Random Video</h3><iframe width="720" height="480" src="http://www.youtube.com/embed/ ' + videos[index] + ' + "&autoplay=1" " frameborder="0" allowfullscreen></iframe></div>';
document.write(html);
});//-->
推荐答案
$(document).ready(function() {
var videos = [
'pRpvdcjkT3k',
'Te4wx4jtiEA',
'efTj6UYzvk4'
];
var index=Math.floor(Math.random() * videos.length);
var html='<div id="video"><h3>Random Video</h3><iframe width="720" height="480" src="http://www.youtube.com/embed/' + videos[index] + '?autoplay=1" frameborder="0" allowfullscreen></iframe></div>';
document.write(html);
});
'?'代替'&'
'?' instead of '&'
这篇关于随机youtube视频自动播放Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文