页面加载时,我需要从选择中显示随机的youtube视频。我发现以下问题非常有帮助,但是我不知道如何将其自动播放。我尝试添加



在“videos [index]”之后,但我无法使其正常工作/不知道是否将其放置在错误的位置。任何帮助将非常感激。

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

});//-->

最佳答案

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

});

'?'代替 '&'

07-28 03:04
查看更多