2014-03-02 126 views
0

我需要在页面加载时显示随机选择的YouTube视频。我发现下面的问题非常有用,但我无法弄清楚如何让它自动播放。我试过后加入Javascript随机youtube视频自动播放

&自动播放= 1

“视频[指数]”但我不能让它的工作/不知道如果我把它错地点。任何帮助将非常感激。

Trying to display a random video on page load

$(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); 

});//--> 
+1

应该没问题,你可以粘贴你的代码,看看你可能会遇到什么问题吗? –

+0

当然,尝试了一些变化,因为我不知道我有正确的语法,页面正在加载和加载,但没有播放,视频加载罚款,当我把自动播出 – user1688604

回答

2
$(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); 

}); 

'?'而不是'&'